剪枝:

1.从后向前枚举

2.迭代加深

然后就0msAC了

//By SiriusRen
#include <cstdio>
using namespace std;
int n,T,s[105];
bool dfs(int t){
if(s[t]==n)return 1;
if(t>=T)return 0;
for(int i=t;i>=1;i--){
s[t+1]=s[i]+s[t];
if(dfs(t+1))return 1;
}
}
int main(){
s[1]=1;
while(scanf("%d",&n)&&n)
for(T=1;;T++)
if(dfs(1)){
for(int j=1;j<=T;j++)
printf("%d ",s[j]);
puts("");break;
}
}

POJ 2248 搜索的更多相关文章

  1. catch that cow POJ 3278 搜索

    catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...

  2. poj 2248 Addition Chains (迭代加深搜索)

    [题目描述] An addition chain for n is an integer sequence with the following four properties: a0 = 1 am ...

  3. 【POJ 2248】 Addition Chain

    [题目链接] http://poj.org/problem?id=2248 [算法] 搜索剪枝 剪枝1 : 优化搜索顺序,从大到小枚举 剪枝2 : Ai + Aj可能相等,只需搜一次即可 剪枝3 : ...

  4. POJ 2248 - Addition Chains - [迭代加深DFS]

    题目链接:http://bailian.openjudge.cn/practice/2248 题解: 迭代加深DFS. DFS思路:从目前 $x[1 \sim p]$ 中选取两个,作为一个新的值尝试放 ...

  5. [Vjudge][POJ][Tony100K]搜索基础练习 - 全题解

    目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练 ...

  6. poj 2251 搜索

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13923   Accepted: 5424 D ...

  7. poj 1011 搜索减枝

    题目链接:http://poj.org/problem?id=1011 #include<cstdio> #include<cstring> #include<algor ...

  8. [POJ 2248]Addition Chains

    Description An addition chain for n is an integer sequence with the following four properties: a0 = ...

  9. Addition Chains POJ - 2248 (bfs / dfs / 迭代加深)

    An addition chain for n is an integer sequence <a0, a1,a2,...,am=""> with the follow ...

随机推荐

  1. Python爬糗百热门20条并邮件分发+wxPython简易GUI+py2app转成可运行文件

    学了一阵子Python,拿来做个什么有意思的东西呢?爬糗百好了.爬到的内容,邮件分发出去. 然后又啃了两天的wxpython,做了个简易的邮件管理界面,能够在这里添加或者删除邮件,而且一键爬虫发送. ...

  2. nyoj--301--递推求值(经典矩阵运算)

    递推求值 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 给你一个递推公式: f(x)=a*f(x-2)+b*f(x-1)+c 并给你f(1),f(2)的值,请求出f(n ...

  3. zzulioj--1712--神秘的数列(水题)

    1712: 神密的数列 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 122  Solved: 92 SubmitStatusWeb Board De ...

  4. Idea配置文件的读取

    开发过程中遇到配置文件读取问题,因此记录以后运用的到. 配置文件位置: 配置文件内容: default_size = 100 grid_size = 20 delayTime = 200 配置文件读取 ...

  5. BZOJ 3569 询问删除指定的k条边后图是否连通 线性基

    思路: 这题思路好鬼畜啊-- 绝对是神思路 //By SiriusRen #include <cstdio> #include <algorithm> using namesp ...

  6. BZOJ 2190 欧拉函数

    思路: 递推出来欧拉函数 搞个前缀和 sum[n-1]*2+3就是答案 假设仪仗队是从零开始的 视线能看见的地方就是gcd(x,y)=1的地方 倒过来一样 刨掉(1,1) 就是ans*2+1 再加一下 ...

  7. Android APP 调试过程中遇到的问题。

    调试过过程中APP安装完启动后有的时候会异常退出,报这个错误.有的时候可以直接启动.查找不到原因.网上说把commit方法替换成commitAllowingStateLoss() 也无效. Andro ...

  8. 【转载】HTTP Session 内存到内存复制的拓扑结构

    http://www.oschina.net/question/129540_23215 HTTP 协议本身是“连接 - 请求 - 应答 - 关闭连接”的模式,是一种无状态协议:然而随着 web 动态 ...

  9. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

  10. css文字超出变省略号...

    <style>.text1 {    width:200px;    overflow:hidden;    text-overflow:ellipsis;    -o-text-over ...