POJ2248 Addition Chains 迭代加深
不知蓝书的标程在说什么,,,,于是自己想了一下。。。发现自己的代码短的一批。。。
限制搜索深度+枚举时从大往小枚举,以更接近n+bool判重,避免重复搜索
#include<cstdio>
#include<iostream>
#include<cstring>
#define R register int
using namespace std;
inline int g() {
R ret=; register char ch; while(!isdigit(ch=getchar()));
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret;
}
int n,dep=;
int a[];
bool v[];
inline bool dfs(int crt) {
if(crt==dep+) return a[dep]==n;
for(R i=crt-;i>=;--i) for(R j=i;j>=;--j) {
if(a[i]+a[j]>n) continue;
if(a[i]+a[j]<=a[crt-]) break;
if(v[a[i]+a[j]]) continue;
a[crt]=a[i]+a[j]; if(dfs(crt+)) return true;
} return false;
}
signed main() {
while(n=g(),n!=) { dep=;
memset(a,,sizeof(a));memset(v,false,sizeof(v)); a[]=;
while(!dfs()) ++dep;
for(R i=;i<=dep;++i) printf("%d ",a[i]); putchar('\n');
}
}
2019.04.26
POJ2248 Addition Chains 迭代加深的更多相关文章
- [POJ2248] Addition Chains 迭代加深搜索
Addition Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5454 Accepted: 2923 ...
- POJ 2248 - Addition Chains - [迭代加深DFS]
题目链接:http://bailian.openjudge.cn/practice/2248 题解: 迭代加深DFS. DFS思路:从目前 $x[1 \sim p]$ 中选取两个,作为一个新的值尝试放 ...
- poj 2248 Addition Chains (迭代加深搜索)
[题目描述] An addition chain for n is an integer sequence with the following four properties: a0 = 1 am ...
- UVA 529 - Addition Chains,迭代加深搜索+剪枝
Description An addition chain for n is an integer sequence with the following four properties: a0 = ...
- Addition Chains POJ - 2248 (bfs / dfs / 迭代加深)
An addition chain for n is an integer sequence <a0, a1,a2,...,am=""> with the follow ...
- C++解题报告 : 迭代加深搜索之 ZOJ 1937 Addition Chains
此题不难,主要思路便是IDDFS(迭代加深搜索),关键在于优化. 一个IDDFS的简单介绍,没有了解的同学可以看看: https://www.cnblogs.com/MisakaMKT/article ...
- [題解](迭代加深)POJ2248_Addition Chains
發現m不會特別大,也就是層數比較淺,所以採用迭代加深 由於xi+xj可能相同,所以開一下vis數組判斷重複 #include<iostream> #include<cstdio> ...
- 「一本通 1.3 例 4」Addition Chains
Addition Chains 题面 对于一个数列 \(a_1,a_2 \dots a_{m-1},a_m\) 且 \(a_1<a_2 \dots a_{m-1}<a_m\). 数列中的一 ...
- UVA 529 Addition Chains(迭代搜索)
Addition Chains An addition chain for n is an integer sequence with the following four propertie ...
随机推荐
- jQuery 给class附点击事件获取对应的索引
有一类div标签,class为pointbox,数量不等,有多个.我需要在点击某一个标签的时候实时获取该标签在这类标签中索引值,以便进行其他操作. 代码很简单: $(".pointbox&q ...
- 557. Reverse Words in a String III 翻转句子中的每一个单词
[抄题]: Given a string, you need to reverse the order of characters in each word within a sentence whi ...
- 18-拍卖叫价(hdu2149 巴什博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=2149 Public Sale Time Limit: 1000/1000 MS (Java/Others) ...
- MySQL - pt-query-digest的下载与使用
对于脚本文件,是可以执行的,我们不用安装.所以,但是这个脚本文件没有执行的权限,所以,我们首先赋予这个脚本文件的可执行的权限. 再次查看文件的信息后. 已经有了执行的权限了. 运行脚本的时候,可要注意 ...
- c语言学习笔记 switch case语句为什么要加break
先来看一个没有break的例子: int main() { int a = 1; switch (a) { case 1: printf("1"); case 2: printf( ...
- 第八课 ROS的空间描述和变换
1.tf的实际应用 1)在机器人的配置中 从上面可以看出激光雷达中心距离机器人底座的中心有20cm,激光雷达的中心距机器人底座中心有10cm,如果激光雷达在障碍物前面0.3米,那么机器人底座离障碍物多 ...
- OpenCV2.3.0在VS中的配置
本文为cherish总结,这里先收藏着了啦啦啦!!! vs中配置时尽量在全局配置中修改,否则每次新建项目都需要重新配置全局配置步骤如下:1.“视图”菜单 -> (其他窗口->)属性管理器 ...
- The Three Models of ASP.NET MVC Apps
12 June 2012 by Dino Esposito by Dino Esposito We've inherited from the original MVC pattern a ra ...
- (转)IIS处理并发请求时出现的问题及解决
原文地址:http://www.cnblogs.com/hgamezoom/p/3082538.html 一个ASP.NET项目在部署到生产环境时,当用户并发量达到200左右时,IIS出现了明显的请求 ...
- ICallbackEventHandler使用
后端:页面需继承ICallbackEventHandler protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack ...