题目
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int dp[N][N];
int v[N], w[N];
int main() {
int n, vm;
cin >> n >> vm;
for (int i = 1; i <= n; i++) {
cin >> v[i] >> w[i];
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= vm; j++)
{
if(v[i] <= j) dp[i][j] = max(dp[i-1][j], dp[i-1][j - v[i]] + w[i]);
else dp[i][j] = dp[i-1][j];
}
}
cout << dp[n][vm];
return 0;
}