对方啥都没说先把你装进了背包
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 }