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 ...
随机推荐
- 475. Heaters 加热范围
[抄题]: Winter is coming! Your first job during the contest is to design a standard heater with fixed ...
- 搭建大数据hadoop完全分布式环境遇到的坑
搭建大数据hadoop完全分布式环境,遇到很多问题,这里记录一部分,以备以后查看. 1.在安装配置完hadoop以后,需要格式化namenode,输入指令:hadoop namenode -forma ...
- logistic growth model . 求解方法 (高斯牛顿法)
https://www.stat.tamu.edu/~jnewton/604/chap4.pdf http://www.metla.fi/silvafennica/full/sf33/sf334327 ...
- sql server行列转化
行列转换: 姓名 课程 分数 张三 语文 74 张三 数学 83 张三 物理 93 李四 语文 74 李四 数学 84 李四 物理 94 想变成(得到如下结果): 姓名 语文 数学 物理 ---- - ...
- git之对比svn
关于git的发展和历史介绍网上有很多资料,大家可以自行去了解,这里给大家一个传送门git介绍在这里我就不多说了.我们今天本篇文章的定位就是帮助大家来了解一下关于git和svn之间的区别及git的安装. ...
- 对request,session,application作用域形象理解
看到一篇比较有意思的文章,分享一下.原网址:http://blog.csdn.net/rushkid02/article/details/8063792 几乎所有的Web开发语言都支持Session功 ...
- Delphi xe7 up1 调用android振动功能
Delphi xe7 up1 调用android振动功能 振动用到以下4个单元: Androidapi.JNI.App,Androidapi.JNIBridge,Androidapi.JNI.Os,A ...
- 我用Django搭网站(3)-表单RSA加密
之前开发项目时因为种种原因一直使用明文提交,表单直接明文提交非常不安全,只要稍加操作就能轻易获取用户的信息.在众里寻他千百度之后决定使用RSA加密方式,简单可靠. 项目准备 一.安装PyCrypto库 ...
- 微信Token验证
/// <summary> /// 微信验证 /// </summary> /// <param name="echostr"></par ...
- 十四、JS同步异步知识点,重点(Node.js-fs模块补充篇)
(本片文章如果你能耐着性子看我,保证会对同步和异步有一个非常深刻的理解) JavaScript是单线程执行,所谓的单线程呢就是指如果有多个任务就必须去排队,前面任务执行完成后,后面任务再执行.因为Ja ...