解题思路:
逐渐求最大值
(模板题,-多阶段决策问题)
注意事项:
遍历是从最大值数组中的1到你拥有的时间t
参考代码:
#include <cstdio>
#include <algorithm>
using namespace std;
int a[10005];
int w[10005];
int f[1000005];
int main()
{
int t,m;
scanf("%d %d",&t,&m);
for(int b = 1; b <= m; b ++)
scanf("%d %d",&a[b],&w[b]);
for(int b = 1; b <= m; b ++)
for(int c = t; c >= a[b]; c--)
f[c]=max(f[c],f[c-a[b]]+w[b]);
f[0] = 0;
for(int b = 1; b<=t; b ++)
f[0]=max(f[0],f[b]);
printf("%d",f[0]);
return 0;
}
0.0分
0 人评分