对方啥都没说先把你装进了背包

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main()
 5 {
 6 int N, M, W, V;
 7 int i, j, temp;
 8 int *F;
 9 scanf("%d %d",&N,&M);
10 F = (int*)calloc(M+1,sizeof(int));
11 for(i=1;i<=N;i++)
12 {
13 scanf("%d %d",&W,&V);
14 for(j=M;j>=W;j--)
15 {
16 temp = F[j-W]+V;
17 F[j] = F[j]>temp?F[j]:temp;
18 }
19 }
20 printf("%d\n",F[M]);
21 return 0;
22 }

 

posted @ 2017-03-02 12:52  明早六点起  阅读(145)  评论(0编辑  收藏  举报