POJ 2248
#include <iostream>
#define MAXN 100
#define min __min using namespace std; int tem[MAXN];
int _min[MAXN]; int n;
int min;
void DFS(int num,int index);
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int k;
int index;
while(cin>>n,n)
{
if(n == )
{
cout<<<<endl;
continue;
}
index = ;
min = ;
tem[index] = ;
index = ;
for(i = index-; i >= ; -- i)
{
if(tem[i] + tem[index-] <= n)
{
tem[index] = tem[i]+tem[index-]; DFS(tem[index],index+);
}
// else
// break; }
for(i = ; i < min-; ++ i)
{
cout<<_min[i]<<" ";
}
cout<<_min[i];
cout<<endl;
}
} void DFS(int num,int index)
{
if(index >= min)
{
return;
}
if(num == n)
{
int i;
if(min > index)
{
for(i = ; i < index; ++ i)
{
_min[i] = tem[i];
}
min = index;
}
return;
} int i;
int k; for(i = index-; i >= ; -- i)
{
if(tem[i] + tem[index-] <= n)
{
tem[index] = tem[i]+tem[index-]; DFS(tem[index],index+);
}
//else
//{
// return;
//}
}
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 2248的更多相关文章
- 【POJ 2248】 Addition Chain
[题目链接] http://poj.org/problem?id=2248 [算法] 搜索剪枝 剪枝1 : 优化搜索顺序,从大到小枚举 剪枝2 : Ai + Aj可能相等,只需搜一次即可 剪枝3 : ...
- POJ 2248 - Addition Chains - [迭代加深DFS]
题目链接:http://bailian.openjudge.cn/practice/2248 题解: 迭代加深DFS. DFS思路:从目前 $x[1 \sim p]$ 中选取两个,作为一个新的值尝试放 ...
- [POJ 2248]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 ...
- 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]< ...
- [zoj] 1937 [poj] 2248 Addition Chains || ID-DFS
原题 给出数n,求出1......n 一串数,其中每个数字分解的两个加数都在这个序列中(除了1,两个加数可以相同),要求这个序列最短. ++m,dfs得到即可.并且事实上不需要提前打好表,直接输出就可 ...
- POJ 2248 搜索
剪枝: 1.从后向前枚举 2.迭代加深 然后就0msAC了 //By SiriusRen #include <cstdio> using namespace std; int n,T,s[ ...
- poj 2248 Addition Chains (迭代加深搜索)
[题目描述] An addition chain for n is an integer sequence with the following four properties: a0 = 1 am ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
随机推荐
- JSP 介绍
Servlet进行逻辑处理效率高,但是页面响应效率低,不太方便. 问题: 在学习了Servlet之后,使用Servlet进行页面的展现,代码书写过于麻烦. 极大的影响了开发的效率,那么有没有一种方式可 ...
- 技术管理zz
1.管理者最重要的是规划Roadmap 技术管理者并不能完全脱离技术.最少要把握最新技术的发展,了解团队当前技术现状和不足.用于规划的时间应该不少于50%的工作时间.具体而言,规划又分为业务规划和团队 ...
- Shiro ini 过滤器
http://shiro.apache.org/web.html#Web-WebINIconfiguration Filter Name Class anon org.apache.shiro.web ...
- 第二届普适计算和信号处理及应用国际会议论文2016年 The 2nd Conference on Pervasive Computing, Signal Processing and Applications(PCSPA, 2016)
A New Method for Mutual Coupling Correction of Array Output Signal 一种阵列输出信号互耦校正的新方法 Research of Robu ...
- 如何使用C++11实现C#属性概念设计
目录(原创博客,版权所有,转载请注明出处 http://www.cnblogs.com/feng-sc) 1.概述 2.C#属性的概念 2.1.简单示例代码介绍C#中的属性 2.2.C++实现效果 ...
- [Android]高低API版本兼容之@TargetApi
使用@TargetApi annotaion, 使高版本API的代码在低版本SDK不报错 例如: AsyncTask.THREAD_POOL_EXECUTOR, 这个静态变量是API11才有的, 设置 ...
- POJ1410_还是没考虑全面——线段是否与矩形有共同的垂直投影
题意如题目 有几个点1.怪我没读好题目:给出的矩形两个端点不一定都是左上右下,但是肯定能勾勒出一个矩形. 2.现在才发现很多线段相交的判断我都没有仔细考虑这一个问题 bool ssinsert(Poi ...
- html隐藏元素
<body> <div>display:元素的位置不被占用</div> <div id="div1" style="displa ...
- 1.WebApi介绍
1.WebApi是什么: WebAPI 是一种用来开发系统间接口.设备接口 API 的技术,基于 Http 协议,请求和返 回格式结果默认是 json 格式.比 WCF 更简单.更通用,比 WebSe ...
- WireShark 查看UDP码流的丢包率
1.用wireshark抓包之后,右击,点decode as,转化为RTP 2. 点show all streams 3.分析