51nod-1086 多重背包
2017-06-03 20:47
113 查看
#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; }
有N种物品,每种物品的数量为C1,C2......Cn。从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi为整数)。求背包能够容纳的最大价值。
Input第1行,2个整数,N和W中间用空格隔开。N为物品的种类,W为背包的容量。(1 <= N <= 100,1 <= W <= 50000)
第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 1
Sample Output
9
相关文章推荐
- AC日记——背包问题 V2 51nod 1086
- 51NOD-1086 背包问题 V2(多重背包)
- 51nod-1086 背包问题(多重背包)
- 51Nod:1086背包问题 V2
- 51nod 1086 背包问题V2 动态规划
- 51nod 1086 背包问题V2(巧妙拆分多重背包)
- 51Nod 1086 背包问题 V2(二进制多重背包)
- 51nod 1086 背包问题 V2 多重背包
- 51Nod 1086 背包问题 V2(二进制多重背包)
- 51nod 1086 背包问题 V2 (多重背包问题)
- 51nod 1086 背包问题V2 (巧妙dp,二进制)
- 【51Nod 1086】背包问题 V2
- 51nod 1086 背包问题 V2
- 51NOD-1086 背包问题 V2
- 多重背包模板 51Nod 1086
- 51nod 1086 背包问题 V2 (多重背包)
- 51nod 1086 背包问题 V2(多重背包)
- 51Nod 1086【背包问题 V2】
- 51nod 1086 背包问题 V2(多重背包问题)
- 51nod 1086 背包问题 V2(多重背包)