【多重背包】HDU 1059 Dividing
来源:互联网 发布:foxmail数据存在哪里 编辑:程序博客网 时间:2024/06/03 06:42
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1059
同时代码里面附有0-1背包、完全背包、多重背包的代码~
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int a[7];int dp[121111];int v,k;void ZeroOnePack(int cost,int weight) { for(int i=v;i>=cost;i--) dp[i] = max(dp[i] , dp[i-cost] + weight); }void CompletePack(int cost,int weight) { for(int i=cost;i<=v;i++) dp[i] = max(dp[i] , dp[i-cost] + weight); }void MultiplePack(int cost,int weight,int amount) { if(cost * amount >= v) CompletePack(cost,weight); else { for(int k=1;k<amount;) { ZeroOnePack(k*cost,k*weight); amount -= k; k <<= 1; } ZeroOnePack(amount*cost,amount*weight); } }int main() { int cas = 1; while(1) { int tot = 0; for(int i=1;i<=6;i++) { scanf("%d",&a[i]); tot += a[i] * i; } if(tot == 0) break; printf("Collection #%d:\n",cas++); if(tot % 2) puts("Can't be divided."); else { v = tot / 2; memset(dp,0,sizeof(dp)); for(int i=1;i<=6;i++) { MultiplePack(i,i,a[i]); } if(dp[v] == v) puts("Can be divided."); else puts("Can't be divided."); } puts(""); } return 0; }
0 0
- hdu 1059 Dividing 多重背包
- hdu 1059 Dividing(多重背包)
- hdu 1059 Dividing(多重背包)
- HDU 1059 Dividing(多重背包)
- hdu 1059 Dividing 多重背包
- Hdu 1059 Dividing -- 多重背包
- hdu 1059 Dividing 多重背包
- HDU-1059-Dividing-多重背包
- HDU-1059 Dividing 多重背包
- hdu 1059 Dividing (多重背包)
- HDU 1059 Dividing 多重背包
- Hdu 1059 Dividing (多重背包)
- HDU 1059 Dividing 多重背包
- hdu-1059-多重背包-Dividing
- HDU 1059 Dividing 多重背包
- HDU 1059 Dividing(多重背包)
- 【多重背包】HDU 1059 Dividing
- hdu 1059 Dividing 多重背包
- ASP.NET前台JS与后台CS函数如何互相调用
- Android 事件处理onTouchEvent,onInterceptTouchEvent ,dispatchTouchEvent
- 《通过Web远程浏览并控制Tiny6410上的usb摄像头》---实战篇
- 开始QT+OpenCV的学习
- 单例模式暴露了我是php程序猿的本质
- 【多重背包】HDU 1059 Dividing
- 水水的博客,华科与西工大的纠结
- 并发队列ConcurrentLinkedQueue与阻塞队列LinkedBlockingQueue的区别
- kvm安装与启动过程说明
- hunnu11472(判有向图是否有有向环)
- 一个动作,多个人感兴趣,存引用
- 【计算几何】HDU 2108 Shape of HDU 凸包
- 2015阿里巴巴校招在线笔试题
- 对getElementsByTagName("*")获取全部元素的总结