HDU1059 Dividing(背包问题)
来源:互联网 发布:网络延迟单位 编辑:程序博客网 时间:2024/05/14 18:05
Dividing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23496 Accepted Submission(s): 6686
Problem Description
Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value.
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.
Input
Each line in the input describes one collection of marbles to be divided. The lines consist of six non-negative integers n1, n2, ..., n6, where ni is the number of marbles of value i. So, the example from above would be described by the input-line ``1 0 1 2 0 0''. The maximum total number of marbles will be 20000.
The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.
The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.
Output
For each colletcion, output ``Collection #k:'', where k is the number of the test case, and then either ``Can be divided.'' or ``Can't be divided.''.
Output a blank line after each test case.
Output a blank line after each test case.
Sample Input
1 0 1 2 0 01 0 0 0 1 10 0 0 0 0 0
Sample Output
Collection #1:Can't be divided.Collection #2:Can be divided.
Source
Mid-Central European Regional Contest 1999
Recommend
JGShining
//多重背包//题意:价值分别为1,2,3,4,5,6的物品的个数分别为 a[1],a[2],````a[6]问能不能分成两堆价值相等的void ZeroOnePack(int cost,int weight)//cost 为费用, weight 为价值 { for(int i=v;i>=cost;i--) if(f[i-cost]+weight>f[i]) f[i]=f[i-cost]+weight;} void CompletePack(int cost,int weight){ for(int i=cost;i<=v;i++) if(f[i-cost]+weight>f[i]) f[i]=f[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); } }
0 0
- HDU1059 Dividing(背包问题)
- hdu1059 Dividing (多重背包)
- hdu1059 Dividing(多重背包)
- HDU1059 Dividing (多重背包)
- HDU1059 Dividing(多重背包)
- ZOJ1149 POJ1014 HDU1059 Dividing,多重背包问题
- hdu1059 Dividing(多重背包+二进制优化)
- hdu1059 Dividing(多重背包+二进制优化)
- HDU1059:Dividing(多重背包二进制优化)
- hdu1059 Dividing(生成函数||背包)
- hdu1059 Dividing 多重背包
- [hdu1059]Dividing 多重背包
- hdu1059 Dividing (多重背包)
- hdu1059 Dividing(完全背包)
- hdu1059 Dividing 【多重背包】
- 动态规划:HDU1059-Dividing(多重背包问题的二进制优化)
- HDU1059 && POJ1014 :Dividing(多重背包)
- hdu1059 &poj1014 Dividing (多重背包)
- fragment
- 学无止境--新浪算法组的博文,都很好
- 线程安全的 C++ Singleton 实现
- 阻塞socket和非阻塞socket(一)
- 年终奖就这么花掉噜:Apple 苹果 ipad mini 4平板电脑 晒单
- HDU1059 Dividing(背包问题)
- linux内核中的排序接口--sort函数
- 【Hibernate】将对象保存到数据库表中
- 颜值才是王道:IKBC - C87 黑色红轴机械键盘
- Android将list数据通过LitePal保存到本地(集合保存到本地)
- 【android笔记】之 android studio 快捷键 (二)
- 172. Factorial Trailing Zeroes详细解答
- Map遍历方法及Map遍历时陷阱
- hdoj4985Little Pony and Permutation