枚举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 迭代加深的更多相关文章

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

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

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

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

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

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

  4. 迭代加深搜索 POJ 1129 Channel Allocation

    POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Acc ...

  5. [poj 2331] Water pipe ID A*迭代加深搜索(dfs)

    Water pipe Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2265 Accepted: 602 Description ...

  6. poj 3134 Power Calculus(迭代加深dfs+强剪枝)

    Description Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multipli ...

  7. 【POJ 2248】 Addition Chain

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

  8. [POJ2248] Addition Chains 迭代加深搜索

    Addition Chains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5454   Accepted: 2923   ...

  9. POJ1129Channel Allocation[迭代加深搜索 四色定理]

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14601   Accepted: 74 ...

随机推荐

  1. 520. Detect Capital判断单词有效性

    [抄题]: Given a word, you need to judge whether the usage of capitals in it is right or not. We define ...

  2. PC建立WIFI热点

    netsh wlan set hostednetwork ssid=test key =12345678netsh wlan start hostednetwork

  3. Linux mii-tool命令

    一.简介 mii-tool 是一个用来查看,管理介质的网络接口的状态的工具. 二.选项 usage: mii-tool [-VvRrwl] [-A media,... | -F media] [int ...

  4. 1.SQL

    Qt和数据库之间的操作非常广泛,Qt支持各种开源和商业的数据库. SQL支持和集成了Qt Model/View结构,让你在GUI编程中更加灵活和方便的使用数据库.

  5. HDU 3723 Delta Wave (高精度+calelan数)

    题意:给定一个图,问你只能向上向下,或者平着走,有多少种方法可以走到最后一个格. 析:首先先考虑,如果没有平的情况就是calelan数了,现在有平的情况,那么就枚举呗,因为数很大,所以要用高精度. 答 ...

  6. duilib入门简明教程 -- 前言(1)

        关于duilib的介绍就不多讲了,一来不熟,二来小伙伴们想必已经对比了多个界面库,也无需赘述.下面进入正题:     不看广告看疗效! 已有众多知名公司采用duilib做为界面库,如华为网盘. ...

  7. MVC c# 调用sql的存储过程

    var hid = new SqlParameter { ParameterName = "HistoryId", Value = history.Id, Direction = ...

  8. angular 管道

    import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'multi' }) export class MultiPipe ...

  9. 苹果微信内置浏览器cookie

    苹果微信内置浏览器cookie会被自动清掉,但safari不会清除,原因还未找到,解决方法是把前端把数据通过header传到后台

  10. docker概述及基础操作

    docker概述 容器技术已经成为应用程序封装和交付的核心技术容器技术的核心有以下几个内核组成CGroups-资源管理NamsSpace-进程管理SElinux-安全 由于是在物理机上实施隔离,启动一 ...