比赛 |
暑假培训B班二测 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
待售干草 |
最终得分 |
100 |
用户昵称 |
Citron酱 |
运行时间 |
0.425 s |
代码语言 |
C++ |
内存使用 |
0.69 MiB |
提交时间 |
2012-07-22 08:34:32 |
显示代码纯文本
#include <cstdio>
#define I_F "hay4sale.in"
#define O_F "hay4sale.out"
const int MAXn=5000+1;
const unsigned int MAXc=50000+1;
int n;
unsigned int c;
unsigned int s[MAXn];
long f[2][MAXc]={{0}};
long ans=0;
inline long Max(const long&, const long&);
void Input();
void Dynap();
void Output();
int main()
{
Input();
Dynap();
Output();
return 0;
}
inline long Max(const long &a, const long &b)
{
return (a>b)?a:b;
}
void Input()
{
freopen(I_F,"r",stdin);
scanf("%d%d",&c,&n);
for (int i=1; i<=n; ++i)
scanf("%d",&s[i]);
}
void Dynap()
{
for (int i=1; i<=n; ++i)
for (unsigned int j=1; j<=c; ++j)
if (s[i]<=j)
f[i%2][j]=Max(f[1-i%2][j],f[1-i%2][j-s[i]]+s[i]);
else
f[i%2][j]=f[1-i%2][j];
for (unsigned int i=1; i<=c; ++i)
ans=Max(ans,f[n%2][i]);
}
void Output()
{
freopen(O_F,"w",stdout);
printf("%ld\n",ans);
}