POJ 1014
#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的更多相关文章
- 证明 poj 1014 模优化修剪,部分递归 有错误
这个问题是存在做.我发现即使是可行的一个问题,但不一定正确. 大部分数据疲软,因为主题. id=1014">poj 1014 Dividing 题目大意:有6堆石头,权重分别为1 2 ...
- POJ 1014 Dividing(多重背包+二进制优化)
http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include&l ...
- DFS(DP)---POJ 1014(Dividing)
原题目:http://poj.org/problem?id=1014 题目大意: 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两 ...
- 背包问题模板,POJ(1014)
题目链接:http://poj.org/problem?id=1014 背包问题太经典了,之前的一篇博客已经讲了背包问题的原理. 这一个题目是多重背包,但是之前的枚举是超时的,这里采用二进制优化. 这 ...
- POJ 1014 / HDU 1059 Dividing 多重背包+二进制分解
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- POJ 1014 Dividing
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...
- AC日记——Dividing poj 1014
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69575 Accepted: 18138 Descri ...
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- 多重背包 (poj 1014)
题目:Dividing 题意:6种重量的的石头,每个给定数量,用总重的一半去装,问能否装满. #include <iostream> #include <algorithm> ...
- POJ 1014 Dividing 多重背包
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 63980 Accepted: 16591 Descri ...
随机推荐
- 二叉树的遍历——Morris
在之前的博客中,博主讨论过二叉树的经典遍历算法,包括递归和常规非递归算法,其时间复杂度和空间复杂度均为O(n).Morris算法巧妙地利用了二叉树的线索化思路,将二叉树的遍历算法的空间复杂度降低为O( ...
- 2018.09.21 codeforces1051D. Bicolorings(线性dp)
传送门 sb线性DP. f[i][j][0/1/2/3]f[i][j][0/1/2/3]f[i][j][0/1/2/3]表示前i列j个连通块且第i列状态为00/01/10/11时的方案总数. 这个显然 ...
- 2018.09.05 bzoj2726: [SDOI2012]任务安排(斜率优化dp+二分)
传送门 跟Ti" role="presentation" style="position: relative;">TiTi为正数的时候差不多. ...
- 2018.07.29~30 uoj#170. Picks loves segment tree VIII(线段树)
传送门 线段树好题. 维护区间取两种最值,区间加,求区间两种历史最值,区间最小值. 自己的写法调了一个晚上+一个上午+一个下午+一个晚上并没有调出来,90" role="prese ...
- 第七章 介词(La préposition )
法语中的介词是将两个同类或非同类的词连接在一起,把一个句中成分同另一个句子成分联系起来,并表明两者之间关系的词类.介词是一种无词性变化的词类. ★介词的形式 ()简单形式的介词,如: ()复合形式的介 ...
- git将本地仓库强制替换掉远程仓库
$ git remote add origin <url> $ git push --force --set-upstream origin master
- linux安装mysql~~~mysql5.6.12
Linux安装mysql服务器 准备: MySQL-client-5.6.12-1.rhel5.i386.rpm MySQL-server-5.6.12-1.rhel5.i386.rpm 首先检查环境 ...
- 关于iOS的自动弹出键盘问题
-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.textField beco ...
- mac下svn无法上传.a文件的问题
Xcode自带的svn和Versions以及一些其它工具都默认ignore".a"文件. 解决办法有两个: 方法一:使用命令行添加文件([转]原文在这) 1.打开终端,输入cd,空 ...
- (KMP 暴力)Corporate Identity -- hdu -- 2328
http://acm.hdu.edu.cn/showproblem.php?pid=2328 Corporate Identity Time Limit: 9000/3000 MS (Java/Oth ...