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.
 
本来我以为是背包  但是超时了   然后搜了题解   发现是动态规划   
好像背包也可以写 但是要用一个新算法    啊啊啊   东西好多   怎么办   学都学不完
 
好吧   先说这一道题
有6快大理石   每一块的价值是1 2 3 4 5 6   给你的六个数是每一个大理石的块数
 深搜搜一下就行了   上代码   一看就明白
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<stdlib.h> using namespace std; #define INF 0xfffffff
#define N 20
int flag,mid,a[N]; void Find(int ans,int s)
{
if(flag)
return;
if(ans==mid)
{
flag=;
return;
}
for(int i=s; i>=; i--)
{
if(a[i])
{
if(ans+i<=mid)
{
a[i]--;
Find(ans+i,i);
if(flag)
break;
}
}
}
return;
} int main()
{
int t=;
while()
{
int sum=;
for(int i=; i<=; i++)
{
scanf("%d",&a[i]);
sum+=a[i]*i;
}
if(sum==)
break;
printf("Collection #%d:\n",t++);
if(sum%==)
{
printf("Can't be divided.\n\n");
continue;
}
flag=;
mid=sum/;
Find(,);
if(flag==)
printf("Can be divided.\n\n");
else
printf("Can't be divided.\n\n");
}
return ;
}

Dividing--hdu1059(动态规划)的更多相关文章

  1. 动态规划--模板--hdu 1059 Dividing

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

  2. 【二进制拆分多重背包】【HDU1059】【Dividing】

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

  3. hdu1059 Dividing ——多重背包

    link:http://acm.hdu.edu.cn/showproblem.php?pid=1059 最简单的那种 #include <iostream> #include <cs ...

  4. poj1014 hdu1059 Dividing 多重背包

    有价值为1~6的宝物各num[i]个,求能否分成价值相等的两部分. #include <iostream> #include <cstring> #include <st ...

  5. hdu1059&poj1014 Dividing (dp,多重背包的二分优化)

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

  6. 转载:hdu 动态规划题集

    1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955     背包;第一次做的时候把概率当做背包(放大100000倍化为整数): ...

  7. hdu 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】(转)

    HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包 ...

  8. [NOIP复习]第三章:动态规划

    一.背包问题 最基础的一类动规问题.相似之处在于给n个物品或无穷多物品或不同种类的物品,每种物品仅仅有一个或若干个,给一个背包装入这些物品,要求在不超出背包容量的范围内,使得获得的价值或占用体积尽可能 ...

  9. 【BZOJ3872】Ant colony(二分,动态规划)

    [BZOJ3872]Ant colony(二分,动态规划) 题面 又是权限题... Description There is an entrance to the ant hill in every ...

  10. 【转载】 HDU 动态规划46题【只提供思路与状态转移方程】

    1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包;第一次做的时候把概率当做背包(放大100000倍化为整数) ...

随机推荐

  1. 洛谷 P2680 运输计划

    题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航道连通了 L 国的所有星球. 小 P 掌管一家 ...

  2. ftp 报错 200 Type set to A

    最近在使用ssis 从ftp服务器抓起文件到本地的时候,发现连接ftp出错 200 Type set to A 解决办法: ftp connection 中 设置UsePassiveMode 为Tru ...

  3. html文本溢出显示省略字符的两种常用方法

    方法一:使用CSS溢出省略的方式解决 解决效果如下: css代码: display: -webkit-box; display: -moz-box; white-space: pre-wrap; wo ...

  4. scriptPubKey and scriptSig

    First of all two matching scripts are used in two different transactions, one that transfers funds t ...

  5. QT+lambda 表达式

    #include "mainwidget.h" #include <QPushButton> #include <QDebug> MainWidget::M ...

  6. HTML习题附答案

    第一章 1.HTML指的是(   A   ). A超文本标记语言(Hyper Text Markup Language) B家庭工具标记语言(Home Tool Markup Language) C超 ...

  7. HTML基础(二)列表标签

    无序列表ul ul标签的格式为 <ul> <li>内容1</li> <li>内容2</li> <li>内容3</li> ...

  8. _vimrc配置

    set nocompatible set encoding=utf8 set guioptions-=T set number set guifont=consolas:h12 source $VIM ...

  9. Android流行界面结构——Fragment通过ViewPager(带指示器)嵌套Fragment结构的创建方法详解

    原创文章,转载请注明出处http://www.cnblogs.com/baipengzhan/p/6287213.html 当前Android流行界面结构的一种——Fragment通过ViewPage ...

  10. 关于flock文件锁的阻塞与非阻塞

    阻塞模式,程序会一直等待. <?php $fp = fopen("lock.txt", "r"); if(flock($fp,LOCK_EX)) { // ...