题意:

a0,a1,a2,a3....an

对于任意的i,j,k

0<=k<=n

0<=i<=k-1

0<=j<=k-1

ak=ai+aj

求a0.....an

解题思路:

迭代加深搜索,限定下界的深搜

首页,利用贪心算法,求出最小的步数depth,an=2ai,当an>=n的时候即可得到最小元素个数,由当前步数一步一步加大搜索的步数.

#include <stdio.h>
#include<iostream>
#include <string.h>
#include<memory.h>
using namespace std;
const int N = ;
int n = ;
int ans[N] = { };
int depth = ;
int flag = ;
void dfs(int cur)
{
if(flag)
return;
if(cur == depth)
{
if(ans[cur] == n)
flag = ;
return;
}
for(int i = ; i <= cur; i++)
{
for(int j = i; j <= cur; j++)
{
if(ans[i] + ans[j] > ans[cur] && ans[i] + ans[j] <= n)
{
int sum = ans[i] + ans[j];
for(int k = cur + ; k <= depth; k++)
sum = sum * ;
if(sum < n)
continue;
ans[cur + ] = ans[i] + ans[j];
dfs(cur + );
if(flag)
return;
}
} }
}
int main()
{
freopen("d://1.txt", "r", stdin);
while (cin >> n && n)
{
memset(ans, , sizeof(ans));
ans[] = ;
int k = ;
depth = ;
flag = ;
while (k < n)
{
++depth;
k = k * ;
}
while (!flag)
{
dfs();
if(!flag)
++depth;
}
cout << ans[];
for(int i = ; i <= depth; i++)
cout << " " << ans[i];
cout << endl;
}
return ;
}

uva-529-枚举的更多相关文章

  1. UVa 12169 (枚举+扩展欧几里得) Disgruntled Judge

    题意: 给出四个数T, a, b, x1,按公式生成序列 xi = (a*xi-1 + b) % 10001 (2 ≤ i ≤ 2T) 给出T和奇数项xi,输出偶数项xi 分析: 最简单的办法就是直接 ...

  2. UVa 140 (枚举排列) Bandwidth

    题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. STL里的next_permutation函数真是好用. 比较蛋疼的就是题目的输入了.. ...

  3. UVa 1151 (枚举 + MST) Buy or Build

    题意: 平面上有n个点,现在要把它们全部连通起来.现在有q个套餐,如果购买了第i个套餐,则这个套餐中的点全部连通起来.也可以自己单独地建一条边,费用为两点欧几里得距离的平方.求使所有点连通的最小费用. ...

  4. Even Parity UVA - 11464 (枚举)

    从来没有觉得枚举有多费脑子的.但是这道题还是很香的. 思路:就是非常简单的枚举啦.   从一般的枚举开始考虑.一般的做法就是在所有的格子中有两种状态1, 0. 而一共有225个格子,所有一共要枚举的情 ...

  5. UVa 1354 枚举子集 Mobile Computing

    只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...

  6. UVA 529 - Addition Chains,迭代加深搜索+剪枝

    Description An addition chain for n is an integer sequence  with the following four properties: a0 = ...

  7. UVA 529 Addition Chains(迭代搜索)

      Addition Chains  An addition chain for n is an integer sequence  with the following four propertie ...

  8. Uva 11754(枚举+中国剩余定理)

    #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...

  9. 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)

    题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...

  10. UVa 10465 Homer Simpson (枚举)

    10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

随机推荐

  1. 安装centos7启动项配置

    安装centos7启动项配置 1.将 setparams 'Install CentOS Linux 7' linuxefi/images/pxeboot/vmlinuz inst.stage2=hd ...

  2. 关于PHP程序员技术职业生涯规划 转自 韩天锋

    转自 http://rango.swoole.com/ 看到很多PHP程序员职业规划的文章,都是直接上来就提Linux.PHP.MySQL.Nginx.Redis.Memcache.jQuery这些, ...

  3. 黄聪:VPS服务器轻松备份工具配置

  4. centos 配置puTTY rsa自动登录

    vim /etc/ssh/sshd_config, 下面三行去掉注释符号# RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysF ...

  5. Excel导出文件流下载

    Controller.cs @CrossOrigin(allowCredentials="true", allowedHeaders="*", methods= ...

  6. uoj#119. 【UR #8】决战圆锥曲线

    http://uoj.ac/problem/119 可以认为数据基本随机,于是可以直接用线段树维护,对每个询问在线段树上进行剪枝搜索. #include<bits/stdc++.h> ty ...

  7. dfs常见的配置文件中的value与description(重要)

    不多说,直接上干货! name value description dfs.namenode.logging.level info The logging level for dfs namenode ...

  8. CSS3 圆角(border-radius)

    值:半径的长度 前缀 -moz(例如 -moz-border-radius)用于Firefox -webkit(例如:-webkit-border-radius)用于Safari和Chrome. 例1 ...

  9. Scrapy学习篇(四)之数据存储

    上一篇中,我们简单的实现了toscrapy网页信息的爬取,并存储到mongo,本篇文章信息看看数据的存储.这一篇主要是实现信息的存储,我们以将信息保存到文件和mongo数据库为例,学习数据的存储,依然 ...

  10. Error detected while processing function pythoncomplete#Complete: 错误解决

    python vim 环境配置好后,莫名奇妙总是出现:Error detected while processing function pythoncomplete#Complete: 恼人的错误,多 ...