POJ 3134 Power Calculus 迭代加深搜索
来源:互联网 发布:linux mysql dump文件 编辑:程序博客网 时间:2024/05/18 03:51
第一发迭代加深搜索,参考网上的。。。
#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int ans, n;int a[15];bool dfs(int dep, int x){ if(a[dep] == n) return true; if(dep == ans) return false; x = max(x, a[dep]); if(x*(1<<(ans-dep)) < n) return false; for(int i = 0; i <= dep; i++) { a[dep+1] = a[i]+a[dep]; if(dfs(dep+1, x)) return true; if(a[i] > a[dep]) a[dep+1] = a[i]-a[dep]; else a[dep+1] = a[dep]-a[i]; if(dfs(dep+1, x)) return true; } return false;}int main(){ while(scanf("%d", &n) != EOF) { if(n == 0) break; if(n == 1) printf("0\n"); else { a[0] = 1; for(ans = 1; ; ans++) { if(dfs(0, 1)) { printf("%d\n", ans); break; } } } } return 0;}
0 0
- POJ 3134 - Power Calculus 迭代加深搜索(DFSID)
- LA 3621 / POJ 3134 Power Calculus (迭代加深搜索)
- POJ 3134 Power Calculus 迭代加深搜索
- poj 3134 Power Calculus(迭代加深dfs)
- poj 3134 Power Calculus(迭代加深dfs)
- POJ-3134-Power Calculus(迭代加深DFS)
- poj3134 Power Calculus---迭代加深dfs
- UVA UVA - 1374 Power Calculus 快速幂计算(迭代加深搜索)
- 1374 - Power Calculus (迭代加深+剪枝)
- UVA - 1374 - Power Calculus(迭代加深)
- POJ 3134 - Power Calculus
- Power Calculus(POJ 3134)
- UVA1374(Power Calculus|快速幂计算)=》迭代加深搜
- 迭代加深搜索——POJ 3134
- POJ 2248 迭代加深搜索
- 迭代加深搜索
- 迭代加深搜索
- 搜索-迭代加深
- POJ 2046 Gap BFS+哈希
- POj 2449 Remmarguts' Date K短路 A*+SPFA
- Plupload初步使用
- Flash开发资料收集
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- POJ 3134 Power Calculus 迭代加深搜索
- 收藏的常用网站整理
- SVM笔记
- WebRTC MCU( Multipoint Conferencing Unit)服务器调研
- 根据hitran数据库计算气体吸收截面 源码
- 设计模式
- 针对当前项目SLED存在短缺XX天
- 安装mysql Install/Remove of the Service Denied!错误的解决办法
- Python - random 模块