多重背包问题 POJ 2392
来源:互联网 发布:深圳蜂鸟软件科技 编辑:程序博客网 时间:2024/06/01 08:11
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;struct block { int height; int maxHeight; int number; bool operator < (const block& b)const { if(maxHeight < b.maxHeight) return true; return false; }};block bList[410];int numList[410][40010];int mHeight = 0;int realHeight = 0;void completePack(int type,int length){ for (int i=length; i<=bList[type].maxHeight; i++) { numList[type][i] = max(numList[type][i],numList[type][i-length]+length); if(realHeight < numList[type][i]) realHeight = numList[type][i]; }}void zeroOnePack(int type,int length,int blockNumber){ for (int i=bList[type].maxHeight; i>=length*blockNumber; i--) { numList[type][i] = max(numList[type][i],numList[type][i-length*blockNumber]+length*blockNumber); if(realHeight < numList[type][i]) realHeight = numList[type][i]; }}void multiplePack(int type,int length,int maxHeight,int blockNumber){ for (int i=1; i<=mHeight; i++) numList[type][i] = numList[type-1][i]; if(length * blockNumber >= mHeight) { completePack(type,length); } int k = 1; while(k < blockNumber) { zeroOnePack(type,length,k); blockNumber -= k; k = k * 2; } zeroOnePack(type,length,blockNumber);}int main(){ int blockNum = 0; while(~scanf("%d",&blockNum)) { memset(numList,0,sizeof(numList)); for (int i=1; i<=blockNum; i++) scanf("%d%d%d",&bList[i].height,&bList[i].maxHeight,&bList[i].number); sort(bList+1,bList+1+blockNum); mHeight = bList[blockNum].maxHeight; for (int i=1; i<=blockNum; i++) multiplePack(i,bList[i].height,bList[i].maxHeight,bList[i].number); printf("%d\n",realHeight); } return 0;}
0 0
- 多重背包问题 POJ 2392
- POJ 2392 Space Elevator (多重背包问题)
- 【多重背包】POJ 2392
- poj 2392 多重背包
- poj 2392 多重背包
- POJ 2392【多重背包】
- POJ 1742 多重背包问题
- POJ 1276 多重背包问题
- poj 1276 多重背包问题
- 多重背包问题 POJ 1014
- POJ 1742多重背包问题
- poj 1014 多重背包问题
- poj 1276 多重背包问题
- POJ 1742 多重背包问题
- poj-1014 多重背包问题
- POJ-1276 多重背包问题
- POJ 2392(多重背包)
- poj 1742 Coins(多重背包可行性问题)
- 关于<%= str%>和<%# str %>两种方式的应用实例
- 使用 NSPropertyListSerialization 持久化字典与数组
- border:none;与border:0;区别
- SVN部署(远程)服务器篇
- ios必备的工具 .
- 多重背包问题 POJ 2392
- 〖IT认证经验〗程序员四大忌
- [XMPP]我是怎么通过直接操作数据来为Openfire注册新用户的
- 推荐系统中的SVD分解
- AsyncImageView 异步下载图片
- google的二维码生成器
- KVC中setValuesForKeysWithDictionary:
- Listview当中:cacheColorHint,android:listSelector属性作用
- Working with NSURLSession: AFNetworking 2.0