Dividing

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22808    Accepted Submission(s): 6444

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.
 
Source
 
题解:6种石头拥有不同价值  现在要求你等分
        输入 n1...ni....n6  代表 价值为i的石头有ni个  若能等分按要求输出 反之亦然
 
题意:背包容量为总价值的一半  若能满足f[m]==m则说明能够等分
        完全背包的二进制优化实现
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll __int64
using namespace std;
int n[];
int m;
int jishu;
int size[];
int value[];
int coun=;
int f[];
void slove(int q)
{
coun=;
for(int i=;i<=q;i++)
{
int c=n[i],v=i;
for (int k=; k<=c; k<<=)
{
value[coun] = k*v;
size[coun++] = k*v;
c -= k;
}
if (c > )
{
value[coun] = c*v;
size[coun++] = c*v;
}
}
}
int main()
{ jishu=;
while(scanf("%d %d %d %d %d %d",&n[],&n[],&n[],&n[],&n[],&n[])!=EOF)
{
if(n[]==&&n[]==&&n[]==&&n[]==&&n[]==&&n[]==)
break;
memset(f,,sizeof(f));
memset(size,,sizeof(size));
memset(value,,sizeof(value));
m=n[]+n[]*+n[]*+n[]*+n[]*+n[]*;
if(m%)
{
printf("Collection #%d:\nCan't be divided.\n\n",++jishu);
}
else
{
slove();
m=m/;
for(int i=;i<=coun-;i++)
for(int k=m;k>=value[i];k--)
{
f[k]=max(f[k],f[k-size[i]]+value[i]);
}
if(f[m]==m)
printf("Collection #%d:\nCan be divided.\n\n",++jishu);
else
printf("Collection #%d:\nCan't be divided.\n\n",++jishu); } }
return ;
}
 
 
 
 

HDU 1059 完全背包的更多相关文章

  1. hdu 1059 (多重背包) Dividing

    这里;http://acm.hdu.edu.cn/showproblem.php?pid=1059 题意是有价值分别为1,2,3,4,5,6的商品各若干个,给出每种商品的数量,问是否能够分成价值相等的 ...

  2. hdu 1059 多重背包

    题意:价值分别为1,2,3,4,5,6的物品个数分别为a[1],a[2],a[3],a[4],a[5],a[6],问能不能分成两堆价值相等的. 解法:转化成多重背包 #include<stdio ...

  3. Dividing (hdu 1059 多重背包)

    Dividing Sample Input 1 0 1 2 0 0 价值为1,2,3,4,5,6的物品数目分别为 1 0 1 2 0 0,求能否将这些物品按价值分为两堆,转化为多重背包.1 0 0 0 ...

  4. D - D 分糖果HDU - 1059(完全背包+二进制优化)

    有两个小朋友想要平分一大堆糖果,但他们不知道如何平分需要你的帮助,由于没有spj我们只需回答能否平分即可. 糖果大小有6种分别是1.2.3.4.5.6,每种若干颗,现在需要知道能不能将这些糖果分成等额 ...

  5. hdu 1059 多重背包 背包指数分块

    思路: 这个方法要看<浅谈几类背包问题>这篇论文. #include"stdio.h" #define Max(a,b) (a)>(b)?(a):(b) ],k[ ...

  6. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

  7. hdu 1059 Dividing bitset 多重背包

    bitset做法 #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a ...

  8. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  9. hdu 5445 多重背包

    Food Problem Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

随机推荐

  1. Linux 内核之api_man 手册安装

    开发环境:Ubuntu18.04,虚拟机virtual box 1.安装XML格式转换 sudo apt  install xmlto 2.在内核目录执行 make mandocs  大概持续了半小时 ...

  2. 使用 MySQL 存储 Hue 元数据

    1.在 MySQL 中增加数据库 hue 2.编辑 hue.ini 文件 [[database]] # Database engine is typically one of: # postgresq ...

  3. 使用Entity Framework时,序列化出错

             在使用Entity Framework时,如果数据库中有两个表是一对多或者是多对多的关系,那么生成的实体类中就有一个导航属性.这个导航属性前面都加上了一个virtual关键字.这个v ...

  4. web开发微信文章目录

    Web开发微信文章目录 2015-12-13 Web开发 本文是Web开发微信的文章目录.通过目录查看文章编号,回复文章编号就能查看文章全文. 回复编号查看全文,搜索分类名可以获得该分类下的文章.   ...

  5. 3招搞定APP注册作弊

    在说如何应对之前,易盾先给各位盾友梳理移动端APP可能遇到哪些作弊风险.1. 渠道商刷量,伪造大量的下载量和装机量,但没有新用户注册:2. 对于电商.P2P.外卖等平台,会面临散户或者团队刷子的注册- ...

  6. weblogic中配置自定义filter和servlet

    情景:最近公司产品要接入其它厂商的单点服务器,本来我是在Tomcat上进行测试,使用的是spring boot 的注解方式@webFilter和@webServlet注解写过滤器和servlet类,启 ...

  7. Linux服务架设篇--traceroute命令

    作用: 查看数据包在传输过程中经过了哪些IP地址的路由器.网关. 工作原理: 首先向远程主机发送TTL为1的UDP数据包,按照协议规定,路由器收到数据包,TTL值减1,这时TTL就为0,路由器就会丢弃 ...

  8. Windows server 2012 R2开机进入cmd,关闭后黑屏问题

    原因分析: 因为自己在卸载IIS的时候,不小心卸载了.net framework,系统没有了图形界面(由完整模式Full变为了核心模式core),需要重新恢复.net framework4.5. 解决 ...

  9. kickstart技术安装操作系统

    kickstart是RedHat公司开源的软件,所以对CentOS兼容性最好. 原理:我们将手动安装的所有的详细步骤记录到一个文件中,然后kickstart通过读取这个文件就可以实现自动化安装系统. ...

  10. 并查集——hdu1232(入门)

    传送门:畅通工程 实质是求连通分支的数量 #include <iostream> #include <cstdio> #include <algorithm> us ...