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 ...
随机推荐
- jquery统计显示或隐藏的元素个数
统计显示的checkbox的数量: 统计隐藏的checkbox数量:
- 2018.07.03 POJ 3348 Cows(凸包)
Cows Time Limit: 2000MS Memory Limit: 65536K Description Your friend to the south is interested in b ...
- yii框架场景的用法
1.在 model 里面定义一下场景 类名必须是 scenarios() public function scenarios() { return [ 'create' => ['title', ...
- LA 4670 Dominating Patterns (AC自动机)
题意:给定n个字符串和一个文本串,查找哪个字符串出现的次数的最多. 析:一匹配多,很明显是AC自动机.只需要对原来的进行修改一下,就可以得到这个题的答案, 计算过程中,要更新次数,并且要映射字符串.如 ...
- mysql操作说明,插入时外键约束,快速删除
快速删除: CMD命令 SET FOREIGN_KEY_CHECKS=0;去除外键约束 truncate table 表名;
- The serializable class XXX does not declare a static final serialVersionUID field of type long
问题: 在Eclipse中,继承类时,总是提示下面的警告(Warning),按理说警告是没有关系的,但是程序看起来老不爽了,这是强迫症的关系(呵呵) The serializable class XX ...
- (最小生成树)Truck History --POJ -- 1789
链接: http://poj.org/problem?id=1789 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2213 ...
- linux环境下(非UI操作)所有软件的安装与卸载总结
UI界面的软件管理 linux下的软件一般都是经过压缩的,主要的格式有这几种:rpm.tar.tar.gz.tgz等.所以首先拿到软件后第一件事就是解压缩. 在xwindow下以rpm格式的软件安装比 ...
- Thread in depth 3:Synchronization
Synchronization means multi threads access the same resource (data, variable ,etc) should not cause ...
- Tempdb--关于表变量的一点疑问和测试
在思考表变量与临时表之间区别时,表变量不会受事务回滚的影响,那么是否意味着表变量无需写入日志呢? 测试方式: 分别对tempdb上的用户表/临时表/表变量 进行10000次插入,查看日志写入次数,使用 ...