發現m不會特別大,也就是層數比較淺,所以採用迭代加深

由於xi+xj可能相同,所以開一下vis數組判斷重複

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=;
int n,x[maxn],ceil;
bool c[];
bool dfs(int dep,int now){
if(dep>ceil)return x[ceil]==n;
for(int i=now-;i>=;i--){
for(int j=i;j>=;j--){//必須從i開始
if(x[i]+x[j]<=x[now-])break;
if(c[x[i]+x[j]])continue;
x[now]=x[i]+x[j];
if(dfs(dep+,now+))return ;
}
}return ;
}
int main(){
while(scanf("%d",&n)!=EOF){
if(n==)break;
ceil=;
memset(x,,sizeof(x));
memset(c,,sizeof(c));
x[]=;
while(!dfs(,))ceil++;
for(int i=;i<=ceil;i++)printf("%d ",x[i]);
printf("\n");
}
}

[題解](迭代加深)POJ2248_Addition Chains的更多相关文章

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

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

  2. C++解题报告 : 迭代加深搜索之 ZOJ 1937 Addition Chains

    此题不难,主要思路便是IDDFS(迭代加深搜索),关键在于优化. 一个IDDFS的简单介绍,没有了解的同学可以看看: https://www.cnblogs.com/MisakaMKT/article ...

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

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

  4. UVA 529 - Addition Chains,迭代加深搜索+剪枝

    Description An addition chain for n is an integer sequence  with the following four properties: a0 = ...

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

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

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

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

  7. usaco4.12Fence Rails(迭代加深)

    为了这题还去学了下迭代加深 回来还是不会写 只好参考各大神的代码及题解了 二分枚举最大可以切的块数 然后就是各种分析及优化 USACO题解里写了7个优化.. 问题分析 抽象一下就可以发现,算法的本质是 ...

  8. poj2286The Rotation Game(迭代加深dfs)

    链接 把迭代加深理解错了 自己写了半天也没写对 所谓迭代加深,就是在深度无上限的情况下,先预估一个深度(尽量小)进行搜索,如果没有找到解,再逐步放大深度搜索.这种方法虽然会导致重复的遍历 某些结点,但 ...

  9. IOI1994 北京2008的挂钟 迭代加深

    总的来讲,这是一道很⑨的题,因为: (1)题目中有⑨个挂钟 (2)有⑨种操作方案 (3)这题因为解空间太小所以可以直接⑨重循环!! 这题可以用迭代加深搜索高效求解,剪枝的策略也很显然: >所求的 ...

随机推荐

  1. Android中高效的显示图片之一 ——加载大图

    在网上看了不少文章,发现还是官方文档介绍最详细,把重要的东西简单摘要出来.详细可看官方文档地址 ( http://www.bangchui.org/read.php?tid=9 ) . 在应用中显示图 ...

  2. Android: 一个两点触控的案例

    下面是一个两点触控的案例代码: package com.zzj; import android.app.Activity; import android.os.Bundle; import andro ...

  3. FFmpeg基础知识之————H264编码profile & level控制

    H.264有四种画质级别,分别是baseline, extended, main, high: 1.Baseline Profile:基本画质.支持I/P 帧,只支持无交错(Progressive)和 ...

  4. ffmpeg用法(心得体会还有你见过的用法)

    ffmpeg的常用用法很多,我这里提供的用法有可能有许多地方是你没见过的. 一.ffmpeg合并视频 我经常需要切割再把一些零碎的视频给拼接起来,这样可以省许多磁盘空间.其实用mencoder挺不错的 ...

  5. 【LeetCode】084. Largest Rectangle in Histogram

    题目: Given n non-negative integers representing the histogram's bar height where the width of each ba ...

  6. BZOJ3307:雨天的尾巴

    浅谈线段树合并:https://www.cnblogs.com/AKMer/p/10251001.html 题目传送门:https://lydsy.com/JudgeOnline/problem.ph ...

  7. @JsonProperty 注解

    是Jackson注解.fastjson有可以用. 作用在字段或方法上,用来对属性的序列化/反序列化,可以用来避免遗漏属性,同时提供对属性名称重命名,比如在很多场景下Java对象的属性是按照规范的驼峰书 ...

  8. 2440移植内核到uboot上,打印乱码

    转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/51851368 可能原因: 1. 修改内核 里的晶振大小 arch\arm\mach ...

  9. LAMP 1.2 Apache编译安装问题解决

    这个错误安装 yum install -y gcc error: mod_deflate has been requested but can not be built due to prerequi ...

  10. Eclipse调试Java程序技巧

    主要步骤.Debug As"->"Java Application".双击设置断点,F5是跳进,F6是执行下一步,F7是跳出 在看这篇文章前,我推荐你看一下Ecli ...