【题目链接】

http://poj.org/problem?id=2248

【算法】

搜索剪枝

剪枝1 : 优化搜索顺序,从大到小枚举

剪枝2 : Ai + Aj可能相等,只需搜一次即可

剪枝3 : 通过观察发现 : m <= 10,可以用迭代加深搜索

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; int i,n,step;
int ans[]; inline bool dfs(int dep)
{
int i,j;
bool visited[];
if (dep > step)
{
if (ans[step] == n) return true;
else return false;
} else
{
memset(visited,false,sizeof(visited));
for (i = dep - ; i >= ; i--)
{
for (j = i; j >= ; j--)
{
if (ans[i] + ans[j] <= ans[i-]) break;
if (ans[i] + ans[j] > n || visited[ans[i]+ans[j]]) continue;
visited[ans[i]+ans[j]] = true;
ans[dep] = ans[i] + ans[j];
if (dfs(dep+)) return true;
}
}
return false;
}
} int main()
{ while (scanf("%d",&n) != EOF && n)
{
ans[] = ;
for (i = ; i <= ; i++)
{
step = i;
if (dfs()) break;
}
for (i = ; i <= step; i++) printf("%d ",ans[i]);
printf("\n");
} return ; }

最新文章

  1. 【代码笔记】iOS-获得富文本设置以后的文字高度
  2. 使用matlab进行空间拟合
  3. 用C#开发ActiveX控件,并使用web调用
  4. 单元测试_JUnit4的应用与实践
  5. Linux下C程序插入执行shell脚本
  6. sqlserver 动态表名 动态字段名 执行 动态sql
  7. jQuery修改操作css属性实现方法
  8. Tomcat无法部署项目
  9. 数据库基础学习3-T-SQL语句
  10. ELK 日志系统搭建配置
  11. Problem F: 分数类的类型转换
  12. JS脚本-零星片段
  13. 微信小程序开发——使用回调函数出现异常:TypeError: Cannot read property &#39;setData&#39; of undefined
  14. Syslog和Windows事件日志收集
  15. 使用Eclipse Memory Analyzer分析Tomcat内存溢出
  16. .NetCore中使用AspectCore、ExceptionLess 实现AOP操作日志记录
  17. Explore Basic Behavior of the TurtleBot ---3
  18. Hadoop MapReduce执行过程实例分析
  19. HDU-4850 Wow! Such String! (构造)
  20. java的反射应用

热门文章

  1. C#——简单工厂
  2. JS——try catch throw
  3. Zynq7000系列之芯片系统结构概述
  4. HDU_5734_数学推公式
  5. java_遍历文件目录
  6. 2019 支付宝App支付 --- PHP
  7. Linux 下phpstudy的安装使用补充说明
  8. windons共享的一些问题
  9. BZOJ 2894: 世界线 广义后缀自动机
  10. java中关于数组的初始化