#include<iostream>
#include<stdio.h>
#define num 6
using namespace std;

bool DFS(int i,int half_sum);
int a[num];
int half_value;
int main()
{
    //freopen("acm.acm","r",stdin);
    int i;
    int sum;
    int time = 0;
    while(1)
    {
        sum = 0;
        for(i = 0; i < num; ++ i)
        {
            cin>>a[i];
        }
        if(!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
            break;
        for(i = 0; i < num; ++ i)
        {
            a[i] %= 30;
            sum += a[i]*(i+1);
        }
        cout<<"Collection #";
        cout<<++ time<<":"<<endl;
        if(sum % 2 != 0)
        {
            cout<<"Can't be divided."<<endl;
            cout<<endl;
            continue;
        }
        half_value = sum / 2;
        if(DFS(0,0))
            cout<<"Can be divided."<<endl;
        else
            cout<<"Can't be divided."<<endl;
        cout<<endl;
    }
}

bool DFS(int i,int half_sum)
{
    int j;
    if(i == 6)
        return false;
    for(j = 0; j <= a[i]; ++ j)
    {
        if(j != 0)
            half_sum += (i+1);
        else
            half_sum += 0;
        if(half_sum == half_value)
            return true;
        else if(half_sum > half_value)
            return false;
        if(DFS(i+1,half_sum))
            return true;
    }
    return false;
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 1014的更多相关文章

  1. 证明 poj 1014 模优化修剪,部分递归 有错误

    这个问题是存在做.我发现即使是可行的一个问题,但不一定正确. 大部分数据疲软,因为主题. id=1014">poj 1014 Dividing 题目大意:有6堆石头,权重分别为1 2 ...

  2. POJ 1014 Dividing(多重背包+二进制优化)

    http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include&l ...

  3. DFS(DP)---POJ 1014(Dividing)

    原题目:http://poj.org/problem?id=1014 题目大意: 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两 ...

  4. 背包问题模板,POJ(1014)

    题目链接:http://poj.org/problem?id=1014 背包问题太经典了,之前的一篇博客已经讲了背包问题的原理. 这一个题目是多重背包,但是之前的枚举是超时的,这里采用二进制优化. 这 ...

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

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

  6. POJ 1014 Dividing

    Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...

  7. AC日记——Dividing poj 1014

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 69575   Accepted: 18138 Descri ...

  8. POJ 1014 Dividing(多重背包)

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

  9. 多重背包 (poj 1014)

    题目:Dividing 题意:6种重量的的石头,每个给定数量,用总重的一半去装,问能否装满. #include <iostream> #include <algorithm> ...

  10. POJ 1014 Dividing 多重背包

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63980   Accepted: 16591 Descri ...

随机推荐

  1. 2018.07.17 HAOI2016 找相同字符(SAM)

    传送门 就是给两个字符串,让你求公共字串的个数. 本来大佬们都是用的广义后缀自动机,但我感觉后缀自动机已经可以做这道题了.我们对其中一个字串建出后缀自动机,然后用另外一个后缀自动机在上面统计贡献即可. ...

  2. ansible api 调用出现ssh交互式输入

    发现在删掉 ~/.ssh/know_hosts 之后运行 ansible api 会出现以下提示 The authenticity of host '10.1.*.* (10.1.*.*)' can' ...

  3. 6) mvn archetype:create-from-project

    cd %old%mvn archetype:create-from-projectcd %old%/target/generated-sources/archetype mvn installcd % ...

  4. (KMP)Simpsons’ Hidden Talents -- hdu -- 2594

    http://acm.hdu.edu.cn/showproblem.php?pid=2594 Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Ja ...

  5. android免root hook框架legend

    一.前言 Android中hook框架已经非常多了,最优秀的当属Xposed和Substrate了,这两个框架我在之前的文章都详细介绍过了,不了解的同学,可以转战这里:http://www.wjdia ...

  6. hdu1089 Ignatius's puzzle

    题目 其实这道题不是很难,但是我刚开始拿到这道题的时候不知道怎么做, 因为这个式子我就不知道是干什么的: 65|f(x) 百度解释(若a/b=x...0  称a能被b整除,b能整除a,即b|a,读作& ...

  7. 洛谷P2633 Count on a tree(主席树上树)

    题目描述 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始为0,即第一个 ...

  8. [Linux-vi] The simple set of vi command

    Source : https://www.cs.colostate.edu/helpdocs/vi.html What is vi? The default editor that comes wit ...

  9. Moving XML/BI Publisher Components Between Instances

    As it is well known fact that XMLPublisher stores the metadata and physical files for templates and ...

  10. 【算法31】寻找数组的主元素(Majority Element)

    题外话 最近有些网友来信问我博客怎么不更新了,是不是不刷题了,真是惭愧啊,题还是在刷的,不过刷题的频率没以前高了,看完<算法导论>后感觉网上很多讨论的题目其实在导论中都已经有非常好的算法以 ...