發現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. oubango中视频JitterBuffer的优化

       

  2. ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...

  3. bzoj 3232: 圈地游戏 01分数规划

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3232 题解: 首先我们看到这道题让我们最优化一个分式. 所以我们应该自然而然地想到01分 ...

  4. 命令行启动nodejs方式 小总结

    之前启动nodejs都是写一个命令行文件,如nodejs.cmd,内容为:start node E:\node\app.js. 今天突然想到之前也用过另外一种方式启动,就是在命令行通过cd命令先找到n ...

  5. MySQL的分页技术总结

    利用子查询示例: SELECT * FROM your_table WHERE id <= (SELECT id FROM your_table ORDER BY id desc LIMIT ( ...

  6. Poj 1316 Self Numbers(水题)

    一.Description In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called se ...

  7. RS-485收发的零延时转换电路

    转自:http://www.dzsc.com/data/html/2007-5-28/41097.html RS-485是一种基于差分信号传送的串行通信链路层协议.它解决了RS-232协议传输距离太近 ...

  8. K-NN回归算法

    from sklearn.datasets import load_iris import numpy as np import matplotlib.pyplot as plt iris = loa ...

  9. Matlab零碎知识

    1.不定积分的求取 int syms x;%为自变量 f=x.^2; s=int(f,x); 其中显示辅助函数simple()和pretty()

  10. 字符串(String)

    字符串是由字符组成的数组,但在JavaScript中字符串是不可变的:可以访问字符串任意位置的文本,但是JavaScript并未提供修改已知字符串内容的方法. 常见功能: obj.length     ...