I Love sneakers! Time Limit:1000msmemory limit:32768kbthis problem'll be judged onHDU. Original id:3033
64-bit integer IO format: %i64d Java class name: Main After months of hard working, Iserlohn finally wins awesome amount of scholarship. As a great zealot of sneakers, he decides to spend all the he money on them in a sneaker store.
There is several brands of sneakers that Iserlohn wants to collect, such as Air Jordan and Nike Pro. And each brand have released various products. For the reason-Iserlohn is definitely a sneaker-mania, he desires-buy at least one product for each brand.
Although the fixed price of each product have been labeled, Iserlohn sets values for each of them based on his own tendency . With handsome but limited, he wants to maximize the total value of the shoes he was going to buy. Obviously, as a collector, he won ' t buy the same product twice.
Now, Iserlohn needs-help him find the best solution of he problem, which means to maximize the total value of the Products he can buy.InputInput contains multiple test cases. Each test case begins with three integers 1<=n<=100 representing the total number of products, 1 <= m<= 10000 The money Iserlohn gets, and 1<=k<=10 representing the sneaker brands. The following N lines each represents a product with three positive integers 1<=a<=k, B and C, 0<=b,c<100000, Meaning the brand s number it belongs, the labeled Price, and the value of this product. Process to End of File.OutputFor each test case, print a integer which is the maximum total value of the sneakers that Iserlohn purchases. Print "Impossible" if Iserlohn ' s demands can ' t be satisfied.Sample Input
5 10000 31 4 62 5 73 4 991 55 772 44 66
Sample Output
255
SourceMulti-university Training Contest 13-host by hits: Do not know what backpack ... Feel like a group 1n backpack ...
1#include <bits/stdc++.h>2 #definePII pair<int,int>3 using namespacestd;4 Const intMAXN = the;5 intn,m,o,dp[ One][10001];6vector< PII >GOODS[MAXN];7 intMain () {8 inta,b,c;9 while(~SCANF (" %d%d%d",&n,&m,&o)) {Ten for(inti =0; i < MAXN; ++i) goods[i].clear (); One for(inti =0; I < n; ++i) { Ascanf" %d%d%d",&a,&b,&c); - Goods[a].push_back (Make_pair (b,c)); - } thememset (dp,-1,sizeofDP); -memset (dp[0],0,sizeofdp[0]); - for(inti =1; I <= o; ++i) { - for(intj =0; J < Goods[i].size (); ++j) { + for(intk = m; K >= Goods[i][j].first; --k) { - if(Dp[i][k-goods[i][j].first] >=0) +Dp[i][k] = max (Dp[i][k],dp[i][k-goods[i][j].first] +goods[i][j].second); A if(dp[i-1][k-goods[i][j].first] >=0) atDp[i][k] = max (dp[i][k],dp[i-1][k-goods[i][j].first] +goods[i][j].second); - } - } - } - if(Dp[o][m] >=0) printf ("%d\n", Dp[o][m]); - ElsePuts"Impossible"); in } - return 0; to}
View Code
HDU 3033 I Love sneakers!