这个题题意是给你价值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. CodeForces 225C Barcode DP

    也是一道dp ,想到了就会觉得很巧妙 矩阵中只有白块和黑块,要求repaint后满足下述条件: 每列一种颜色 根据输入范围x, y 要求条纹宽度在[x, y] 之间 数据范围: n, m, x and ...

  2. (Problem 14)Longest Collatz sequence

    The following iterative sequence is defined for the set of positive integers: n n/2 (n is even) n 3n ...

  3. (Problem 13)Large sum

    Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...

  4. jsp字段判空

    是对象吧String jsp的写法 <% if(str == null) { %> str is null <% } else { %> str not null <% ...

  5. c语言memset详解

    void *memset(void *s, int ch, size_t n);(int ch可以是char或int) 将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值, 块的 ...

  6. VM添加e1000e驱动网卡

    关闭虚拟机 打开VMware 虚拟机配置 (.vmx),如

  7. 【Demo 0025】注册/反注册窗体类RegisterClassEx/UnregisterClass

    所有窗体在创建前都必须注册窗体类,只有注册的窗体类才被系统认知并允许实例化,换句话说通过注册告诉进程窗体管理器此类窗体的属性如: 背景色,窗体上的鼠标样式以及窗体事件处理函数等;  有一些控件类系统自 ...

  8. 黑马程序员 ---> 正则表达式

    --------------- ASP.Net+Android+IO开发S..Net培训.期待与您交流! --------------- 正则表达式 一.概述: 1.概念:符合一定规则的表达式. 2. ...

  9. BZOJ 1014: [JSOI2008]火星人prefix( splay + hash )

    用splay维护序列, 二分+hash来判断LCQ.. #include<bits/stdc++.h> using namespace std; typedef unsigned long ...

  10. JAVA刚碰见的问题( java.lang.SecurityException: The jurisdiction policy files are not signed by a trusted signer)

    原文:刚碰见的问题 1.  failed to load the jni shared library jre bin server jvm.dll 解决:这个主要是eclipse的版本和安装的jdk ...