题目
思路
1.状态及指标:d(i,j),遍历到第i个数,还剩钱数,值为乘积
2.状态转移方程:
代码
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define _for(i,a,b) for(int i = (a); i<(b); i++)
#define _rep(i,a,b) for(int i = (a); i<=(b); i++)
using namespace std;
const int maxn = 30000+100;
int n, C, d[maxn];
int main(){
scanf("%d%d",&C,&n);
int V,W;
_rep(i,1,n){
scanf("%d%d",&V,&W);
_rep(j,0,C)
if(j + V <= C)
d[j] = max(d[j],d[j+V]+W*V);
}
int ans = 0;
_rep(i,0,C) ans = max(ans,d[i]);
printf("%d\n",ans);
return 0;
}