Ppoj 1014 深搜
这个题题意是给你价值1-6的珠宝个数输出能否平分为两份(如果平分为三分就不知道怎么做了……)
主要是用回溯DFS,但是要剪枝,对200取模……!!(很重要……)
代码……
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib> using namespace std; int n[];
bool flag;
int aver; void dfs(int num,int t){
if(flag)
return;
if(num == aver){
flag = ;
return;
} for(int i = t;i <= ;i++){
if(n[i] && num + i <= aver){
n[i]--;
dfs(num+i,i);
n[i]++;
if(flag)
return;
}
}
} int main()
{
//freopen("input.txt","r",stdin);
int cas = ;
while(){
int sum = ;
for(int i = ;i <= ;i++){
cin >> n[i];
n[i] %= ;
sum += (i*n[i]);
}
if(sum == )
break;
cout << "Collection #" << cas++ << ":" << endl;
if(sum % == ){
cout << "Can't be divided." << endl << endl;
continue;
}
aver = sum /;
flag = ;
dfs(,);
if(flag){
cout << "Can be divided." << endl << endl;
}
else{
cout << "Can't be divided." << endl << endl;
}
}
return ;
}
Ppoj 1014 深搜的更多相关文章
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- 2015暑假多校联合---Cake(深搜)
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
- 深搜+回溯 POJ 2676 Sudoku
POJ 2676 Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17627 Accepted: 8538 ...
- 深搜+DP剪枝 codevs 1047 邮票面值设计
codevs 1047 邮票面值设计 1999年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description ...
- 【wikioi】1049 棋盘染色(迭代深搜)
http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...
- poj1190 生日蛋糕(深搜+剪枝)
题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...
随机推荐
- tomcat虚拟主机虚拟目录配置
今天着实要记上一笔,需要配置tomcat虚拟目录的问题 一 首先看两个名词 appBase -- 顾名思义 就是你app所在的目录,目录下面的子目录将自动被部署为应用:war被解压并部署 docBas ...
- 如何用vs查看结构体布局
今天遇到一个问题: 假设在每个系统的structA 结构不同,我们在windbg看了以后直接拿来用,自己定义成结构体,如何来验证这个结构体内存布局是否和windbg一致. 当然笨办法是自己一个个成员数 ...
- Rsync、Unison及DRBD的比较
一.Rsync Rsync(remote synchronize),顾名思义,可以知道这是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的 “Rsync算法”来 ...
- 使用zxing生成二维码 - servlet形式
因为项目有个功能需要打印二维码,因为我比较喜欢使用html+css+js实现,所以首先想到的是jquery.qrcode.js插件,这个插件可以用canvas和table生成二维码,效果也不错,不过对 ...
- 完整的yuicompressor单个压缩和批量压缩以及gzip再次压缩,拦截器的配置等
下载地址:http://yuilibrary.com/download/yuicompressor/ 个人认为现在yuicompressor是最安全,最值得信赖的压缩工具,至少到现在没出现过问题 1. ...
- debian支持ll命令
debian支持ll命令 $ ll -bash: ll: command not found 没有ll这个命令.尽管也知道ll事实上 是ls -l 这个命令的别名,可是总感觉不是非常习惯.由于之前一直 ...
- PostgreSQL正则表达式查询
参考http://www.php100.com/manual/PostgreSQL8/functions-matching.html LIKE string LIKE pattern [ ESCAPE ...
- Android GsonUtils工具类
有那么一个开源jar包,叫gson 可以很方便的将java中的对象和字符串相互转化,数据传输和处理的时候,用到的可能性很大 https://github.com/google/gson http:// ...
- android handler looper thread
在线程中调用包含创建handler方法的时候,会报错,提示: “need call Looper.prepare()” -- 在创建之前,调用Looper.prepare()方法来创建一个looper ...
- mysql 行锁排查
<pre name="code" class="html">mysql 锁表: 隔离级别使用RR: mysql> SELECT @@GLOBA ...