【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

结论:每次只用新生成的数字就好了。
然后就是IDA*了。
迭代深搜+剪枝。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
#include <bits/stdc++.h>
using namespace std; int n,maxdep; vector <int> v;
int pre[30]; bool dfs(int dep){
if (dep == maxdep){
if (count(v.begin(),v.end(),n)) return true;
return false;
}
int now = v.back();
int delta = maxdep - dep;
if (now*pre[delta]<n) return false;
for (int i = (int) v.size()-1;i >= 0;i--){
int temp = v[i] + now;
if (count(v.begin(),v.end(),temp)==false){
v.push_back(temp);
if (dfs(dep+1)) return true;
v.pop_back();
} temp = now - v[i];
if (count(v.begin(),v.end(),temp)==false){
v.push_back(temp);
if (dfs(dep+1)) return true;
v.pop_back();
}
}
return false;
} int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
pre[0] = 1;
for (int i = 1;i < 30;i++) pre[i] = pre[i-1]*2;
ios::sync_with_stdio(0),cin.tie(0);
while (cin >>n && n){
v.clear();
v.push_back(1);
for (maxdep = 0; ;maxdep++){
if (dfs(0)){
cout << maxdep << endl;
break;
}
}
}
return 0;
}

最新文章

  1. IKAnalyzer
  2. FILE不是C语言关键字
  3. c#语句 随堂练习1
  4. jvm classLoader architecture :
  5. Redis 设计与实现读书笔记一 Redis List
  6. 解决 winform 界面对不齐 z
  7. IBM Python 技术专题
  8. Ubuntu 14.04 LAMP搭建(Apache 2.47+MySQL 5.5+PHP5.5)
  9. 求数组的最小数、最大值,求一组数的平均数,sort函数详解,类数组转数组
  10. 从canvas理解面向对象
  11. 浅谈web移动端适配问题
  12. 一张图解释NIO原理
  13. Desert King POJ - 2728(最优比率生产树/(二分+生成树))
  14. Docker中安装elasticsearch6.7.1
  15. html5 服務器發送事件
  16. vue watch bug记录
  17. Unity shader学习之菲涅耳反射
  18. 深入云存储系统Swift核心组件:Ring实现原理剖析
  19. MySQL Workbench 的安全设置
  20. YOLO V2论文理解

热门文章

  1. C/C++(C++返回对象与应用区别,类成员的存储)
  2. DataGirdView 常用操作
  3. JBoss配置连接池
  4. 用YourAPP开发网络状态提醒应用
  5. Android引入library失败的可能原因
  6. OpenCV特征点检测&mdash;&mdash;Surf(特征点篇)&amp;flann
  7. Ansible学习记录一:Linux下部署
  8. vmstat---有关进程、虚存、页面交换空间及 CPU信息
  9. JNDI学习总结(2)——JNDI数据源的配置
  10. ln用法