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 ...
随机推荐
- Topic modeling【经典模型】
http://www.cs.princeton.edu/~blei/topicmodeling.html Topic models are a suite of algorithms that unc ...
- Ubuntu18.04创建新的系统用户
目标: 1.为测试学习Docker,在虚拟机OS为18.04里,创建一个系统账号,账号名称:docker 2.在/home下有新建username的文件夹 一.建立账号 1.以root账号登录 2.u ...
- Luogu 5043 【模板】树同构([BJOI2015]树的同构)
BZOJ 4337 简单记录一种树哈希的方法:以$x$为根的子树的哈希值为$\sum_{y \in son(x)}f_y*base_i$,$f_y$表示以$y$为根的树的哈希值,其中$i$表示$f_y ...
- 对于 yii2 高级模板 生成文件入口
安装的 advanced 模板web下是没有index.php 方法: 在advanced 目录下有个init.bat 应用程序 双击即可如下 查看advanced 目录 (刷新)如下 已有:
- jquery 遮罩层指定位置
.css .datagrid-mask-msg { position: absolute; top: %; margin-top: -20px; padding: 12px 5px 10px 30px ...
- 整合Office Web Apps至自己的开发系统
原文出处:http://www.cnblogs.com/poissonnotes/p/3267190.html 还可参考:https://www.cnblogs.com/majiang/p/36729 ...
- css总结17:HTML块级元素&行内元素之分: <div> 和<span>
1 HTML 区块元素: 大多数 HTML 元素被定义为块级元素或内联元素. 1.1 块级元素实例: <div> <h1>, <p>, <ul>, &l ...
- linux 下运行 tomcat
一开始找不到表名,原来mysql 表名区分大小写. 修改参数 lower_case_table_names=1 成功运行后不能通过浏览器访问! 开启8080端口 一.关闭防火墙 firewall-cm ...
- 在UIWebView中添加自定义编辑菜单
如何在UIWebView中添加自定义的编辑菜单困扰了很久.没想到意外的简单! 现在很多的内容提供类应用中,长按内容页会选中按的单词并且显示一个编辑菜单.如图: 独乐乐不如众乐乐.一篇好文章是需要大家一 ...
- c#帮助类:发送邮件
private static string IsOpenSendMail = ConfigurationManager.AppSettings["IsOpenSendMail"]; ...