poj 2392 Space Elevator(多重背包)
2017-08-15 22:17
381 查看
先排序,再背包。
可转成完全背包
可转成完全背包
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int MAXN = 500; int dp[MAXN*100]; struct block { int h,a,c; }; block bs[MAXN]; bool cmp(const block& a, const block& b) { return a.a < b.a; } void ZeroOnePack(int w, int v, int W) { for(int j = W; j >= w; --j) dp[j] = max(dp[j],dp[j-w]+v); } int main() { int k,sum = 0;; scanf("%d",&k); for(int i = 0; i < k; ++i) scanf("%d %d %d",&bs[i].h,&bs[i].a,&bs[i].c); sort(bs,bs+k,cmp); for(int i = 0; i < k; ++i) { if(bs[i].h*bs[i].c >= bs[i].a) { for(int j = bs[i].h; j <= bs[i].a; ++j) dp[j] = max(dp[j-bs[i].h]+bs[i].h,dp[j]); } else { int temp = bs[i].c; for(int k = 1; k <= temp; k *=2) { ZeroOnePack(k*bs[i].h,k*bs[i].h,bs[i].a); temp -= k; } if(temp) ZeroOnePack(temp*bs[i].h,temp*bs[i].h,bs[i].a); } } int res = 0; for(int i = bs[k-1].a; i >= 0; --i) res = max(res,dp[i]); printf("%d\n",res); }
相关文章推荐
- POJ 2392 Space Elevator(多重背包)
- POJ 2392 Space Elevator (多重背包 + 思路题)
- poj 2392 Space Elevator(dp 排序+多重背包)
- POJ_2392 Space Elevator(多重背包)
- POJ 2392-Space Elevator(多重背包)
- POJ 2392 Space Elevator(多重背包变形)
- POJ 2392 Space Elevator(多重背包)
- poj 2392 Space Elevator(多重背包)
- poj2392 Space Elevator(多重背包)
- poj 2392 Space Elevator (多重背包)
- POJ_2392 Space Elevator(多重背包)
- POJ - 2392 Space Elevator(多重背包)
- POJ 2392 Space Elevator(贪心+多重背包)
- poj 2392 Space Elevator(排序+多重背包)
- POJ 2392-Space Elevator(多重部分和-多重背包)
- POJ 题目2392 Space Elevator(多重背包)
- poj 2392 Space Elevator(多重背包+先排序)
- POJ 2392 Space Elevator (多重背包+优化)
- POJ 2392 Space Elevator(多重背包)
- poj 2392 Space Elevator(多重背包)