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 ...
随机推荐
- 2018.07.22 codeforces750E(线段树维护状态转移)
传送门 给出一个数字字串,给出若干个询问,询问在字串的一段区间保证出现2017" role="presentation" style="position: re ...
- day06(Collection,List,ArrayList,LinkedList,iterator迭代器,增强for)
Collection 接口 方法实现 boolean add(Object o);//添加 boolean remove(Object o);//移除 修改方法 让实现类自己去实现修 ...
- (KMP)Simpsons’ Hidden Talents -- hdu -- 2594
http://acm.hdu.edu.cn/showproblem.php?pid=2594 Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Ja ...
- gridview的编辑,更新,取消,自动分页等
gridview编辑列,把左下角的"自动生成字段"的复选框的勾去掉 添加boundfield(绑定列)将其datafield设置为productname,headertext设置为 ...
- 1028. Hanoi Tower Sequence
1028. Hanoi Tower Sequence Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Hanoi Tow ...
- 基于注解方式@AspectJ的AOP
启用对@AspectJ的支持 Spring默认不支持@AspectJ风格的切面声明,为了支持需要使用如下配置: <aop:aspectj-autoproxy/> 这样Spring就能发现@ ...
- EBS查找当前Form文件
http://www.cnblogs.com/benio/archive/2011/06/10/2077289.html 我们经常会要在ORACLE EBS中寻找我们正在浏览的form页面的执行文件, ...
- [Linux]几个armhf的ubuntu源
摘自百度贴吧,留存 http://mirrors.ustc.edu.cn/ubuntu-ports/http://ftp.ubuntu-tw.org/mirror/ubuntu-ports/http: ...
- C# 图像自动切换
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- c# 1-2+3-4.....求和
找规律: 下界:1 上界:n class Program { static void Main(string[] args) { ; ; i <=; i++) { ==) { sum -= i; ...