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.10.20 loj#2593. 「NOIP2010」乌龟棋(多维dp)
传送门 f[i][j][k][l]f[i][j][k][l]f[i][j][k][l]表示用iii张111,jjj张222,kkk张333,lll张444能凑出的最大贡献. 然后从f[i−1][j][ ...
- 2018.07.28 uoj#164. 【清华集训2015】V(线段树)
传送门 线段树好题. 要求支持的操作: 1.区间变成max(xi−a,0)" role="presentation" style="position: rela ...
- 多块盘制作成一个lvm
1.创建pv[root@autodeploy nfs]# pvcreate /dev/vdd1WARNING: xfs signature detected on /dev/vdd1 at offse ...
- webservice大文件怎么传输
版权所有 2009-2018荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webapp/up6.2/in ...
- linux cpu过高原因及代码定位
1. top命令查看CPU和内存占用率 top回车,然后按1 发现进程PID 35163 CPU和内存占用率都很高 top - 06:13:47 up 5:31, 1 user, load av ...
- PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- Linux 输入输出(I/O)重定向
目录 1.概念 Linux 文件描述符 2.输出重定向 格式 示例 注意 3.输入重定向 格式 示例 4.自定义输入输出设备 解释 示例 最后说两句 1.概念 在解释什么是重定向之前,先来说说什么是文 ...
- Need You Now --Lady Antebellum
战地女神(Lady Antebellum)由女主唱 Hillary Scott.男主唱 Charles Kelley .吉他/键盘手 Dave Haywood,2006夏天在美国乡村音乐重镇纳什维尔组 ...
- ORACLE 管道技术应用
但是使用管道函数的时候是可以返回一个package里面定义的type的. create or replace package test_typeis type test_type_record ...
- iOS Development和iOS Distribution有什么区别
http://zhidao.baidu.com/link?url=T9od33JuA7jjxzfyV-wOjuVLSNUaqpc9aoCu2HjfYfHBuRLW1CNDii0Bh9uvG6h-GeJ ...