51nod 1086 背包问题 V2
来源:互联网 发布:二维数组去除重复 编辑:程序博客网 时间:2024/05/18 03:11
#include <bits/stdc++.h>using namespace std;long long dp[2][50050],cost[110],val[110],num[110],c[770],v[770];int main(){long long n,w,i,j,x,cnt;while(cin>>n>>w){for(i=1;i<=n;i++)scanf("%lld%lld%lld",&cost[i],&val[i],&num[i]);cnt=1;for(i=1;i<=n;i++){x=1;while(x<=num[i]){c[cnt]=cost[i]*x;v[cnt]=val[i]*x;cnt++;num[i]-=x;x<<=1;}if(num[i]){c[cnt]=cost[i]*num[i];v[cnt]=val[i]*num[i];cnt++;}}memset(dp,0,sizeof(dp));for(i=1;i<cnt;i++){for(j=1;j<=w;j++){if(j<c[i])dp[i&1][j]=dp[i&1^1][j];elsedp[i&1][j]=max(dp[i&1^1][j],dp[i&1^1][j-c[i]]+v[i]);}} printf("%lld\n",dp[cnt&1^1][w]);}}
0 0
- 【51Nod 1086】背包问题 V2
- 51 Nod 1086 背包问题 V2
- 51nod 1086 背包问题 V2
- 51nod 1086 背包问题 V2
- 51Nod 1086【背包问题 V2】
- 51NOD-1086 背包问题 V2
- 背包问题 V2 (51Nod
- 51nod 1086 背包问题 V2(多重背包问题)
- 51nod oj 1086 背包问题 V2 【多重背包问题】
- 51nod 1086 背包问题 V2 (多重背包问题)
- 51Nod 1086背包问题V2(多重背包)
- 51Nod 1086 背包问题 V2(二进制多重背包)
- 51nod 1086 背包问题 V2(多重背包)
- 51nod 1086 背包问题V2(巧妙拆分多重背包)
- 51nod 1086 背包问题 V2 多重背包
- 51nod 1086 背包问题v2 多重背包
- 51nod 1086 背包问题 V2(多重背包)
- 51Nod 1086 背包问题 V2(多重背包)
- 51nod 1085 背包问题
- Java之处理流
- NOIP2013复赛提高组day1(A:转圈游戏 B:火柴排队 C:货车运输)
- ROS语音合成-----sound_play应用
- 超键,候选键,主键
- 51nod 1086 背包问题 V2
- php异常处理
- 51NOD 1402 最大值 By Assassin
- VR,AR与MR区别,技术交流兴趣部落
- 缘
- 51nod 1087 1 10 100 1000
- 背包问题
- 51nod 1088 最长回文子串
- interrupt、interrupted 、isInterrupted 区别