hdu 1059 完全背包
来源:互联网 发布:淘宝退款能申请几次 编辑:程序博客网 时间:2024/06/05 17:21
Dividing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 27091 Accepted Submission(s): 7763
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.
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.
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.
Sample Input
1 0 1 2 0 0
1 0 0 0 1 1
0 0 0 0 0 0
Sample Output
Collection #1:
Can’t be divided.
Collection #2:
Can be divided.
完全背包模板题
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int dp[2000050];void beg01(int V,int v,int w){ for(int i=V;i>=v;i--){ dp[i]=max(dp[i],dp[i-v]+w); }}void begcomplete(int V,int v,int w){ for(int i=v;i<=V;i++){ dp[i]=max(dp[i],dp[i-v]+w); }}void begmul(int V,int v,int w,int num){ if(v*num>V){ begcomplete(V,v,w); return; } int k=1; while(k<=num){ beg01(V,v*k,w*k); num-=k; k=k*2; } beg01(V,v*num,w*num);}int main(){ int a1,a2,a3,a4,a5,a6; int h=0; while(cin>>a1>>a2>>a3>>a4>>a5>>a6){ if(!a1&&!a2&&!a3&&!a4&&!a5&&!a6){ break; } int sum=(a1*1+a2*2+a3*3+a4*4+a5*5+a6*6); if(sum%2){ printf("Collection #%d:\n",++h); printf("Can't be divided.\n\n"); } else { sum/=2; memset(dp,0,sizeof(dp)); begmul(sum,1,1,a1); begmul(sum,2,2,a2); begmul(sum,3,3,a3); begmul(sum,4,4,a4); begmul(sum,5,5,a5); begmul(sum,6,6,a6); if(dp[sum]==sum){ printf("Collection #%d:\n",++h); printf("Can be divided.\n\n"); } else { printf("Collection #%d:\n",++h); printf("Can't be divided.\n\n"); } } } return 0;}
- hdu 1059 完全背包
- hdu 1059 Dividing(完全背包)
- HDU 1059 01背包+完全背包=多重背包
- 01背包+完全背包 HDU
- hdu 1059 有限物品完全背包
- hdu 1114 完全背包
- hdu 1114 完全背包
- HDU-1114 完全背包
- HDU 1114 完全背包
- HDU 1114 完全背包
- hdu 1114完全背包
- 完全背包 HDU 1114
- hdu 1114 完全背包
- hdu 4508 (完全背包)
- hdu 1114 (完全背包)
- hdu 1248 完全背包
- hdu 1248(完全背包)
- hdu 2191 完全背包
- Laravel : Syntax error or access violation: 1055 Error
- zookeeper的单机和伪集群myid中的数字是唯一标识
- eclipse开发Android新建工程文件中每个文件代表的含义
- JAVA系统之间通信方式总结
- 纯虚函数
- hdu 1059 完全背包
- 难用的vertical-align
- 希尔排序--Java版
- 为什么在覆盖equals时一定也要覆盖hashCode
- 微信开发 公众号接入服务器
- C++sort()函数的用法
- pyspider爬虫设置延时
- Memcached stats查看状态
- 《图解HTTP》整理(6)