#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. servlet-servletContext网站计数器

    1.在项目中新建文件夹新建文件nums.txt 2.在web.xml文件配置 <servlet>     <description>This is the descriptio ...

  2. 2018.10.05 NOIP模拟 相遇(dfs序+lca)

    传送门 考虑到两条路径相交的条件: 设两条路径为a,ba,ba,b. 则要么aaa路径的lcalcalca在bbb上. 要么bbb路径的lcalcalca在aaa上. 因此我们维护两棵树. 分别支持路 ...

  3. 2018.07.03 POJ 2318 TOYS(二分+简单计算几何)

    TOYS Time Limit: 2000MS Memory Limit: 65536K Description Calculate the number of toys that land in e ...

  4. 2018.09.05 bzoj1010: [HNOI2008]玩具装箱toy(斜率优化dp)

    传送门 一道经典的斜率优化dp. 推式子ing... 令f[i]表示装前i个玩具的最优代价. 然后用老套路. 我们只考虑把第j+1" role="presentation" ...

  5. springcloud-eureka简单实现

    请参考 spring+cloud为服务实战 第三章 一.创建Eureka服务 1.使用Idea创建一个项目 结构如下: 2.pom.xml配置: <?xml version="1.0& ...

  6. Redis为什么是单线程

    转自:https://www.zhihu.com/question/23162208 https://www.zhihu.com/question/55818031:加了一些个人的理解. Redis为 ...

  7. 201709021工作日记--Volley源码详解(五)

    学习完了CacheDispatcher这个类,下面我们看下NetworkDispatcher这个类的具体细节,先上代码: /** * 提供一个线程执行网络调度的请求分发 * Provides a th ...

  8. C语言中线程和进程的区别

    线程是指进程内的一个执行单元也是进程内的可调度的实体,与进程的区别 1) 调度:线程作为调度和分配的基本单位,进程作为拥有资源的基本单位 2) 并发性:不仅进程之间可以并发执行,同一个进程之间的多个线 ...

  9. Reactor 模式在Netty中的应用

    Reactor 模式在Netty中的应用 典型的Rector模式 mainReactor 服务端创建成功后,会监听Accept操作,其中ServerSocketchannel中的PipeLine中现在 ...

  10. volatile 类型修饰符

    volatile 类型修饰符 1.解释 就像大家更熟悉的const一样,volatile是一个类型修饰符(type specifier).它是被设计用来修饰被不同线程访问和修改的变量.如果不加入vol ...