POJ - 2248 迭代加深
枚举ak的值
反向枚举使ak尽快到达最短链的n
/*H E A D*/
int n,m,a[23333],dep;
bool dfs(int x){
if(a[x-1]>n||a[x-1]<=a[x-2])return 0;
if(x>dep){
if(a[x-1]==n) return 1;
else return 0;
}
// rep(i,1,x-1){
// rep(j,1,x-1){
rrep(i,x-1,1){
rrep(j,x-1,i){
a[x]=a[i]+a[j];
if(dfs(x+1))return 1;
}
}
return 0;
}
int main(){
IOS;
while(cin>>n){
if(n==0)break;
if(n==1){
cout<<1<<endl;
continue;
}
a[1]=1;
rep(depth,2,oo){
dep=depth;
if(dfs(2)){
rep(i,1,depth-1) cout<<a[i]<<" ";
cout<<a[depth]<<endl;
break;
}
}
}
return 0;
}
UPD:UVa上的TLE了啊,待我摸鱼过后再改改
POJ - 2248 迭代加深的更多相关文章
- POJ 2248 - Addition Chains - [迭代加深DFS]
题目链接:http://bailian.openjudge.cn/practice/2248 题解: 迭代加深DFS. DFS思路:从目前 $x[1 \sim p]$ 中选取两个,作为一个新的值尝试放 ...
- Addition Chains POJ - 2248 (bfs / dfs / 迭代加深)
An addition chain for n is an integer sequence <a0, a1,a2,...,am=""> with the follow ...
- poj 2248 Addition Chains (迭代加深搜索)
[题目描述] An addition chain for n is an integer sequence with the following four properties: a0 = 1 am ...
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- [poj 2331] Water pipe ID A*迭代加深搜索(dfs)
Water pipe Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2265 Accepted: 602 Description ...
- poj 3134 Power Calculus(迭代加深dfs+强剪枝)
Description Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multipli ...
- 【POJ 2248】 Addition Chain
[题目链接] http://poj.org/problem?id=2248 [算法] 搜索剪枝 剪枝1 : 优化搜索顺序,从大到小枚举 剪枝2 : Ai + Aj可能相等,只需搜一次即可 剪枝3 : ...
- [POJ2248] Addition Chains 迭代加深搜索
Addition Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5454 Accepted: 2923 ...
- POJ1129Channel Allocation[迭代加深搜索 四色定理]
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14601 Accepted: 74 ...
随机推荐
- Java中迭代Map的方法
Map<String, String> mapServlet = new HashMap<String, String>(); System.out.println(" ...
- logistic growth model . 求解方法 (高斯牛顿法)
https://www.stat.tamu.edu/~jnewton/604/chap4.pdf http://www.metla.fi/silvafennica/full/sf33/sf334327 ...
- Luogu 4213 【模板】杜教筛(Sum)
当作杜教筛的笔记吧. 杜教筛 要求一个积性函数$f(i)$的前缀和,现在这个东西并不是很好算,那么我们考虑让它卷上另外一个积性函数$g(i)$,使$(f * g)$的前缀和变得方便计算,然后再反推出这 ...
- 500 Internal Server Error
解决策略: 1.httpd.conf中,开启apache头信息自定义模块 2.htaccess文件,对这个域名的资源进行访问时,添加一个头信息 Header set Access-Control-Al ...
- nodelet的理解
1.介绍 nodelet包可以为在相同进程中的多个算法之间实现零拷贝的传输方式. 这个包也提供了实现一个nodelet所需的nodelet基类以及用于实例化nodelet的NodeletLoader类 ...
- C# -- 泛型(1)
简介: 先看看泛型的概念--“通过参数化类型来实现在同一份代码上操作多种数据类型.利用“参数化类型”将类型抽象化,从而实现灵活的复用”. 很多初学者在刚开始接触泛型的时候会比较难理解 “泛型” 在这里 ...
- 【转】微信中MMAlert(半透明底部弹出菜单)的使用介绍
原文地址:http://blog.csdn.net/singwhatiwanna/article/details/8892930 果大家时常用过微信或者用过iphone,就会发现有种从底部弹出的半透明 ...
- Log--检查各数据库日志的使用情况
-- Recovery model, log reuse wait description, log file size,-- log usage size and compatibility lev ...
- C# 多线程操作实例
1.多线程操作 一旦打开线程就必须记得关闭 1.第一部分 这是个数字叠加小功能 private void CountTo(int countTo, CancellationToken ct) { ; ...
- C# 属性与字段
属性和字段的区别: 属性是逻辑字段,是字段的扩展,并不占用实际的内存:而字段占用内存空间. 属性可以被其他类访问:而非public的字段不能被直接访问. 属性可以对接受的数据在范围上做限定:而字段不能 ...