poj 3134 Power Calculus (IDA*)
来源:互联网 发布:eplan软件价格 编辑:程序博客网 时间:2024/05/22 15:23
题意:求由X得到X^n的最少步数。
分析:迭代加深搜索。
剪枝:1、如果大于当前限制的深度,停止搜索。
2、如果当前的数通过自身相乘(即指数相加 最快方式)都不能达到n,停止搜索。
感想:
写到后来越来越像什么用dfs搜索某个集合的幂集中有多少元素,取和不取某个数,然后继续搜。。
真的很像啊。。。虽然我每次都写不好DFS。。。
#include<cstdio>using namespace std;int vis[2010];int flag,deep,n;void dfs(int pos){ int t; if(pos>deep || (vis[pos]<<(deep-pos))<n || flag) return; if(vis[pos]==n) { flag=1; return; } for(int i=1;i<=pos;i++) { if(flag) return; t=vis[pos]+vis[i]; if(t>0 && t<2000) { vis[pos+1]=t; dfs(pos+1); } t=vis[pos]-vis[i]; if(t>0 && t<2000) { vis[pos+1]=t; dfs(pos+1); } }}int main(){ while(scanf("%d",&n)&&n) { deep=0,flag=0; vis[1]=1; while(!flag) { deep++; dfs(1); } printf("%d\n",deep-1); } return 0;}
0 0
- poj 3134 Power Calculus(IDA*)
- poj 3134 Power Calculus (IDA*)
- POJ 3134Power Calculus(IDA*)
- POJ 3134 Power Calculus (IDA*)
- poj 3134 Power Calculus (IDA*)
- POJ 3134 - Power Calculus
- Power Calculus(POJ 3134)
- poj3134 Power Calculus IDA*
- poj 3134Power Calculus (IDAstar)
- POJ 3134 - Power Calculus (IDDFS)
- POJ 3134 Power Calculus 笔记
- UVA 1374 Power Calculus(IDA*)
- 【IDA*】POJ3134[Power Calculus]题解
- poj 3134 Power Calculus iddfs(迭代深搜)
- UVa 1374 - Power Calculus <IDA*算法>
- UVa 1374 - Power Calculus(IDA*)
- UVa 1374:Power Calculus(IDA*)
- UVA - 1374 Power Calculus(IDA*+剪枝)
- hdu2337 Escape From Enemy Territory---二分bfs+预处理
- 正则表达式的奥秘
- spinner下拉列表
- 什么是JSON文件,java中如何从里面存取数据
- 生成最短摘要
- poj 3134 Power Calculus (IDA*)
- 任务定时器
- 如何: 自动发送表单数据到 Internet Explorer
- 【深入Java虚拟机】之六:Java语法糖
- springmvc入门
- linux下RAR的安装和使用
- 使用AlertDialgo创建自定义对话框
- 最牛B的编码套路
- Java知识总结-内部类