模板题解
#include <iostream>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
int main(){
int N=0, V=0, v[1005], w[1005];
int dp[1005][1005];
cin >> N >> V;
for(int i=1; i<=N; ++i){
cin >> v[i] >> w[i];
}
for(int i=1; i<=N; ++i){
for(int j=0; j<=V; ++j){
dp[i][j]=dp[i-1][j];
if(j>=v[i])
dp[i][j]=max(dp[i-1][j], dp[i][j-v[i]]+w[i]);
}
}
cout << dp[N][V] << endl;
return 0;
}
f[i, j] = max(f[i-1, j], f[i, j-v]+w);