点击打开链接链接

Dividing

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 17544    Accepted Submission(s): 4912

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
 
Recommend
JGShining

给出价值分别为1 2 3 4 5 6 的石头的个数 问能不能平分

一个容量为sum/2的背包

#include<cstdio>
#include<cstring>
int maxn(int a,int b)
{
return a>b?a:b;
}
int cnt[10];
int w[22222];
int dp[22222];
int main()
{
int sum;
int cas=1;
int xx;
while(scanf("%d",&cnt[0])!=EOF)
{
sum=cnt[0];
for(int i=1;i<6;i++)
{
scanf("%d",&cnt[i]);
sum+=cnt[i]*(i+1);
}
if(!sum)
break;
xx=0;
for(int i=0;i<6;i++)
{
for(int j=1;j<=cnt[i];j*=2)
{
w[xx++]=j*(i+1);
cnt[i]-=j;
}
if(cnt[i])
{
w[xx++]=cnt[i]*(i+1);
cnt[i]=0;
}
}
printf("Collection #%d:\n",cas++);
//printf("%d\n",sum);
if(sum%2)
{
printf("Can't be divided.\n");
}
else
{
memset(dp,0,sizeof(dp));
for(int i=0;i<xx;i++)
{
for(int j=sum/2;j>=w[i];j--)
{
dp[j]=maxn(dp[j],dp[j-w[i]]+w[i]);
}
}
//printf("%d\n",dp[sum/2]);
if(dp[sum/2]==sum/2)
{
printf("Can be divided.\n");
}
else
{
printf("Can't be divided.\n");
}
}
puts("");
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

hdu 1059 Dividing 多重背包的更多相关文章

  1. hdu 1059 Dividing(多重背包优化)

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. POJ 1014 / HDU 1059 Dividing 多重背包+二进制分解

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...

  3. HDU 1059(多重背包加二进制优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=1059 Dividing Time Limit: 2000/1000 MS (Java/Others)    Me ...

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

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

  5. hdu 1059 Dividing bitset 多重背包

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

  6. HDU 1059 Dividing 分配(多重背包,母函数)

    题意: 两个人共同收藏了一些石头,现在要分道扬镳,得分资产了,石头具有不同的收藏价值,分别为1.2.3.4.5.6共6个价钱.问:是否能公平分配? 输入: 每行为一个测试例子,每行包括6个数字,分别对 ...

  7. Hdu 1059 Dividing & Zoj 1149 & poj 1014 Dividing(多重背包)

    多重背包模板- #include <stdio.h> #include <string.h> int a[7]; int f[100005]; int v, k; void Z ...

  8. ACM学习历程—HDU 1059 Dividing(dp && 多重背包)

    Description Marsha and Bill own a collection of marbles. They want to split the collection among the ...

  9. 题解报告:hdu 1059 Dividing(多重背包、多重部分和问题)

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...

随机推荐

  1. 采用Flume实时采集和处理数据

    它已成功安装Flume在...的基础上.本文将总结使用Flume实时采集和处理数据,详细过程,如下面: 第一步,在$FLUME_HOME/conf文件夹下,编写Flume的配置文件,命名为flume_ ...

  2. 更多RANK37

    By LTL 经过对BDG长期的观察得出的这套理论,希望能对大家学习OI有所帮助. 入门篇 首先在掌握一门语言时(P,C都无所谓的),假设不习惯指针能够直接无视.语言之中对于入门选手来说最重要的递归. ...

  3. Codeforces Round #274 (Div. 2) B. Towers

    As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting o ...

  4. atitit.为什么技术的选择方法java超过.net有前途

    atitit.为什么技术的选择方法java超过.net有前途 #----有没有法律依据不同的铜需求... 通常有开发效率,需要在稳定性.. 笔者 老哇爪 Attilax 艾龙,  EMAIL:1466 ...

  5. 打包静默安装参数(nsis,msi,InstallShield,InnoSetup)

    原文:打包静默安装参数(nsis,msi,InstallShield,InnoSetup)[转] 有时我们在安装程序的时候,希望是静默安装的,不显示下一步下一步,这编访问来教大家如何来操作,现在常用的 ...

  6. 接收一个IT招聘促销信息,试着想参加,有兴趣的可以携手并进,共同。

    时隆重举行! 招聘的企业: (个人认为,中智.也买酒还是非常有吸引力的) watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHdia2Zj/font/5a6L ...

  7. 数据库文档生成工具——word2chm,SqlSpec

    首先使用代码生成器可以生成word版本的数据库文档. 转成chm格式的更加小巧和方便~ SqlSpec是个好工具,可以生成所有数据库相关的信息 之后可以一键生成chm文档.

  8. SAE+Java+jetty

    SAE的java执行环境jetty如servlet该容器,和开放几乎完全访问.有效支持各种jar包.但对于jdk的要件的版本号是非常严格格,这里的版本号是jdk1.6 SAE利用上传war该方式配置j ...

  9. Android手游《》斗地主完整的源代码(支持单机和网络对战)

    Android手游<斗地主>完整的源代码(支持单机和网络对战)下载.一个很不错的源代码. 斗地主掌游是一个独特的国内社会斗地主棋牌游戏,之后玩家可以下载网上斗地主和全世界.掌游斗地主特点: ...

  10. BST(Binary Search Tree)

    原文链接:http://blog.csdn.net/jarily/article/details/8679280 /****************************************** ...