I love sneakers!
64-bit integer IO format: %I64d Java class name: Main
There are several brands of sneakers that Iserlohn wants to collect, such as Air Jordan and Nike Pro. And each brand has released various products. For the reason that Iserlohn is definitely a sneaker-mania, he desires to buy at least one product for each brand.
Although the fixed price of each product has been labeled, Iserlohn sets values for each of them based on his own tendency. With handsome but limited money, he wants to maximize the total value of the shoes he is going to buy. Obviously, as a collector, he won’t buy the same product twice.
Now, Iserlohn needs you to help him find the best solution of his problem, which means to maximize the total value of the products he can buy.
Input
Output
Sample Input
5 10000 3 1 4 6 2 5 7 3 4 99 1 55 77 2 44 66
Sample Output
255
Source
1 #include <bits/stdc++.h> 2 #define pii pair<int,int> 3 using namespace std; 4 const int maxn = 110; 5 int n,m,o,dp[11][10001]; 6 vector< pii >goods[maxn]; 7 int main(){ 8 int a,b,c; 9 while(~scanf("%d %d %d",&n,&m,&o)){ 10 for(int i = 0; i < maxn; ++i) goods[i].clear(); 11 for(int i = 0; i < n; ++i){ 12 scanf("%d %d %d",&a,&b,&c); 13 goods[a].push_back(make_pair(b,c)); 14 } 15 memset(dp,-1,sizeof dp); 16 memset(dp[0],0,sizeof dp[0]); 17 for(int i = 1; i <= o; ++i){ 18 for(int j = 0; j < goods[i].size(); ++j){ 19 for(int k = m; k >= goods[i][j].first; --k){ 20 if(dp[i][k - goods[i][j].first] >= 0) 21 dp[i][k] = max(dp[i][k],dp[i][k-goods[i][j].first] + goods[i][j].second); 22 if(dp[i-1][k - goods[i][j].first] >= 0) 23 dp[i][k] = max(dp[i][k],dp[i-1][k-goods[i][j].first] + goods[i][j].second); 24 } 25 } 26 } 27 if(dp[o][m] >= 0) printf("%d\n",dp[o][m]); 28 else puts("Impossible"); 29 } 30 return 0; 31 }