题目:http://acm.hdu.edu.cn/showproblem.php?pid=4508
#include <iostream> #include <stdlib.h> typedef struct FOOD { int value; int heat; float weight; }; FOOD food[100001]; int f[100001]; int main() { int V,n; int i,j; int max_value,sum_heat; while(scanf("%d",&n)!=EOF) { for(i =0;i<n;i++) { scanf("%d %d",&food[i].value,&food[i].heat); } scanf("%d",&V); for(i =0;i<=V;i++) f[i] =0; for(i =0;i<n;i++) { for(j=food[i].heat;j<=V;j++) { if(f[j] < f[j-food[i].heat] + food[i].value) f[j] = f[j-food[i].heat] + food[i].value; } } printf("%d\n",f[V]); } return 0; }