I Love sneakers!Time
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4253 Accepted Submission (s): 1735
Problem descriptionafter 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
Source2009 multi-university Training Contest 13-host by hits
Recommendgaojie | We have carefully selected several similar problems for you:3535 2415 3449 3035 3036 AC Code
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX (A, B) (a>b?a:b) struct S{int w , V;} Sn[20][1001];int Num[200],dp[20][10100];int Main () {int n,m,k;while (scanf ("%d%d%d", &n,&m,&k)!=EOF) {int I,j,k;memset (num,0,sizeof (num)); for (i=0;i<n;i++) {int a,b,c;scanf ("%d%d%d", &a,&b,&c); Sn[a][num[a] ].w=b;sn[a][num[a]].v=c;num[a]++;} Memset (Dp,-1,sizeof (DP)); for (i=0;i<=m;i++) dp[0][i]=0;for (k=1;k<=k;k++) {for (i=0;i<num[k];i++) {for (J=M; j>=sn[k][i].w;j--) {if (dp[k][j-sn[k][j].w]!=-1) Dp[k][j]=max (DP[K][J],DP[K][J-SN[K][I].W]+SN[K][I].V); if (dp[ K-1][j-sn[k][j].w]!=-1) Dp[k][j]=max (DP[K][J],DP[K-1][J-SN[K][I].W]+SN[K][I].V);}} if (dp[k][m]==-1) printf ("impossible\n"); elseprintf ("%d\n", Dp[k][m]);}}
Hdoj topic 3033 I Love sneakers! (group backpack)