cheng_you_know

学而时习之!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

题目: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;
}
posted on 2013-06-16 16:40  cheng_you_know  阅读(154)  评论(0编辑  收藏  举报