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 ...
随机推荐
- 18-printf(*)的输出格式
#include <bits/stdc++.h> using namespace std; int main(){ for(int i = 0; i < 26; i++){ cout ...
- Luogu 4254 [JSOI2008]Blue Mary开公司
BZOJ 1568 学习了一波李超线段树. 大佬blog 这个东西专门用来维护插入一条线段和区间/单点的最大/最小值. 插入的时候讨论: 1.如果当前结点上没有线段,那么直接插入. 2.如果当前结点上 ...
- 500 Internal Server Error
解决策略: 1.httpd.conf中,开启apache头信息自定义模块 2.htaccess文件,对这个域名的资源进行访问时,添加一个头信息 Header set Access-Control-Al ...
- CopyOnWriteArrayList原理
http://blog.csdn.net/chayangdz/article/details/76347465 总结的很到位: http://www.cnblogs.com/java-zhao/p/5 ...
- CodeForces 489E Hiking (二分+DP)
题意: 一个人在起点0,有n个休息点,每个点有两个数值,分别表示距离起点的距离xi,以及所获得的愉悦值bi,这个人打算每天走L距离,但实际情况不允许他这么做.定义总体失望值val = sum(sqrt ...
- Socket编程(c语言示例)
转自:http://blog.csdn.net/dxpqxb/article/details/8166423 前言 Socket可以看成在两个程序进行通讯连接中的一个端点,是连接应用程序和网络驱动程序 ...
- 博客迁移到http://pengliu.cf
博客迁移到http://pengliu.cf
- 操作文件方法简单总结(File,Directory,StreamReader,StreamWrite ) - Zery-zhang
一 基本介绍 操作文档,文件夹,需要用到的类 1 Directory (静态类) : 用于创建.移动和删除等操作通过 目录 和子 目录 DirectoryInfo (非静态): 2 File ...
- C# 由范式编程==运算符引发对string内存分配的思考
今天在看C#编程指南时(类型参数的约束http://msdn.microsoft.com/zh-cn/library/d5x73970.aspx)看到一段描述: 在应用 where T : class ...
- 一个div添加多个背景图片
效果图如下: