这个题题意是给你价值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 深搜的更多相关文章

  1. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  2. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  3. 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 ...

  4. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  5. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  6. 深搜+回溯 POJ 2676 Sudoku

    POJ 2676 Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17627   Accepted: 8538 ...

  7. 深搜+DP剪枝 codevs 1047 邮票面值设计

    codevs 1047 邮票面值设计 1999年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description ...

  8. 【wikioi】1049 棋盘染色(迭代深搜)

    http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...

  9. poj1190 生日蛋糕(深搜+剪枝)

    题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...

随机推荐

  1. windows和centos用cutycapt截网页的图

    centos下:(主要参考http://loosky.net/2816.html) (1)安装qt47 增加qt47的源 vim /etc/yum.repos.d/atrpms.repo //加入如下 ...

  2. ZOJ 3331 Process the Tasks 双塔Dp

    用dp[i][j]表示当前安排好了前i个任务,且机器A和机器B完成当前分配到的所有任务的时间差为j(这里j可正可负,实现的时候需要加个offset)时,完成这些任务的最早时间.然后根据j的正负,分别考 ...

  3. docker学习笔记14:Dockerfile 指令 ENV介绍

    ENV指令用来在镜像构建过程中设置环境变量.我们来看一个Dockerfile的例子: #test FROM ubuntu MAINTAINER hello ENV MYDIR /mydir RUN m ...

  4. 15个最受欢迎的Python开源框架

    以下是伯乐在线从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框 ...

  5. JAVA爬虫 WebCollector

    JAVA爬虫 WebCollector 爬虫简介: WebCollector是一个无须配置.便于二次开发的JAVA爬虫框架(内核),它提供精简的的API,只需少量代码即可实现一个功能强大的爬虫. 爬虫 ...

  6. win7删除桌面文件需要刷新才会消失(2种解决方法)

    有没有遇到过这种情况,删除桌面文件没有效果,要点右键的刷新删除过的文件才会在桌面上消失!解决方法有两种: 第一种方法 点击"开始→运行",在对话框中输入"regedit& ...

  7. android4.4组件分析--service组件

    6       Service 6.1            service介绍 6.1.1.            基本介绍 Service是Android四大组件之中的一个(其余的是activit ...

  8. AsyncTask究竟需要多少个线程

    最起码两个:主线程和工作线程; 可以参考:http://zhidao.baidu.com/link?url=ho4UEcEbaogRZUFHwig1neSKR25b2zT9iXyM36hEgWTmvJ ...

  9. TortoiseSVN (一) - 疑难操作

    引用: http://blog.sina.com.cn/s/blog_74c22b210101cy3s.html   一.由于Unity打包过程需要耗费很长的时间,在测试过程中如果只需测某几种功能,则 ...

  10. aop编程 环绕round

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...