#include<iostream>
#include<cmath>
using namespace std;
const int N = 1010;
int v[N] = { 0 }, w[N] = { 0 };
int dp[N][N] = { 0 };
int main()
{
int n, V,i,j;
cin >> n >> V;
for (i = 1; i <= n; i++)
cin >> v[i] >> w[i];
for (i = 1; i <= n; i++) {
for (j = 0; j <= V; j++) {
if (j < v[i])
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - v[i]] + w[i]);
//与01背包问题代码区别--dp[i][j - v[i]] + w[i]->可以重复选择相同的商品
}
}
cout << dp[n][V];
return 0;
}
完全背包问题
最新推荐文章于 2024-11-07 23:24:07 发布