Consumer
解法:有依赖的背包问题#include
#include
using namespace std;
int dp[100010], tmp[100010];
int max(int a, int b){return a>b?a:b;}
int n, m, p, w, v, tot;
int main()
{
while(scanf("%d%d", &n, &tot)!=EOF)
{
memset(dp, 0, sizeof(dp));
for(int i=0;i<n;i++)
{
scanf("%d%d", &p, &m);
memcpy(tmp, dp, sizeof(dp));
for(int j=0;j=w;k--)
tmp[k] = max(tmp[k], tmp[k-w]+v);
}
for(int j=p;j<=tot;j++)
dp[j] = max(dp[j], tmp[j-p]);
}
printf("%d\n", dp[tot]);
}
return 0;
}