| 记录编号 | 32087 | 评测结果 | AAAAAAAAAAA | ||
|---|---|---|---|---|---|
| 题目名称 | 395.[USACO Oct09] Bessie 的体重问题 | 最终得分 | 100 | ||
| 用户昵称 | 是否通过 | 通过 | |||
| 代码语言 | C++ | 运行时间 | 0.071 s | ||
| 提交时间 | 2011-11-05 12:07:16 | 内存使用 | 0.36 MiB | ||
#include <cstdio>
using namespace std;
int main(void)
{
freopen("diet.in","r",stdin);
freopen("diet.out","w",stdout);
int i=0,j=0,n=0,maxwei=0,temp=0,a[500]={0},f[45001]={0};
scanf("%d %d\n",&maxwei,&n);
for (i=0;i<n;i++)
scanf("%d\n",&a[i]);
for (i=0;i<n-1;i++)
for (j=maxwei;j>=a[i];j--)
{
temp=a[i]+f[j-a[i]];
if (temp>f[j])
f[j]=temp;
}
temp=a[i]+f[maxwei-a[i]];
if (temp>f[maxwei])
f[maxwei]=temp;
printf("%d\n",f[maxwei]);
fclose(stdin);
fclose(stdout);
return(0);
}