#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define maxn 1005
#define maxv 10005
using namespace std;
long long dp[maxn][maxv];
int capcity[maxn];
int value[maxn];
int main()
{
//freopen("data.in","r",stdin);
ios::sync_with_stdio(false);
memset(capcity,0,sizeof(capcity));
memset(dp, 0, sizeof(dp));
int v;
int n;
cin >> n >> v;
for (int i = 0; i < n; i++)
{
cin >> capcity[i] >> value[i];
}
dp[0][0] = 0;
for(int i = 1; i <= n; ++i)
{
for(int j = 0; j <= v; ++j)
{
if(j >= capcity[i-1])
{
dp[i][j] = max(dp[i-1][j], dp[i][j - capcity[i-1]] + value[i-1]);
}
else
{
dp[i][j] = dp[i-1][j];
}
}
}
cout << dp[n][v] << endl;
return 0;
}
计蒜客 蒜头君的购物袋3(DP)
最新推荐文章于 2020-09-29 17:27:33 发布