版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq1059752567/article/details/72854329
#include <stdio.h>
#include <string.h>
#include <ctime>
#include <stack>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define lowbit(x) (x&-x)
#define mem(x,d) memset(x,d,sizeof(x))
const int maxn = 1e5+5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
int dp[maxn];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=0; i<n; i++)
{
int w,v,c,k;
scanf("%d%d%d",&w,&v,&c);
for(k=1; k<=c; k<<=1)
{
int u = k*w;
for(int j=m; j>=u; j--)
dp[j] = max(dp[j],dp[j-u]+k*v);
c -= k;
}
if(!c) continue;
int u = w*c;
for(int j=m; j>=u; j--)
dp[j] = max(dp[j],dp[j-u]+c*v);
}
cout<<dp[m]<<endl;
}
return 0;
}
第2 - N + 1行,每行3个整数,Wi,Pi和Ci分别是物品体积、价值和数量。(1 <= Wi, Pi <= 10000, 1 <= Ci <= 200) Output输出可以容纳的最大价值。 Sample Input
3 6 2 2 5 3 3 8 1 4 1Sample Output
9