UVA 1374 Power Calculus
来源:互联网 发布:进入编程模式错误 编辑:程序博客网 时间:2024/06/08 02:40
IDA*求解。
程序代码:
#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#include <map>using namespace std;const int maxn = 1010;int n, maxd;int arr[110];bool check(int x, int len) { for(int i = 0; i < len; ++i) { if(arr[i] == x) { return true; } } return false;}int get_max(int len) { int ans = -1; for(int i = 0; i < len; ++i) { ans = max(ans, arr[i]); } return ans;}bool dfs(int cur) { if(cur == maxd) { if(check(n, cur + 1)) { return true; } return false; } int h = get_max(cur + 1); if(h*(1<<(maxd-cur)) < n) return false; //if(arr[cur] < n) { for(int i = cur; i >= 0; --i) { if(arr[cur] < n) { arr[cur+1] = arr[i] + arr[cur]; if(dfs(cur + 1)) return true; } arr[cur+1] = arr[cur] - arr[i]; if(arr[cur+1] <= 0) continue; if(dfs(cur + 1)) return true; } //} return false;}int main() { //freopen("aa.in", "r", stdin); while(scanf("%d", &n) != EOF) { if(n == 0) break; if(n == 1) { printf("0\n"); } else { for(maxd = 1; ; ++maxd) { arr[0] = 1; if(dfs(0)) { printf("%d\n", maxd); break; } } } } return 0;}
0 0
- UVa 1374 Power Calculus
- UVA 1374 Power Calculus
- UVA - 1374 Power Calculus
- uva 1374 Power Calculus
- uva 1374 power calculus
- UVA 1374 Power Calculus
- uva 1374 Power Calculus
- UVA 1374 - Power Calculus(迭代深搜)
- uva 1374 - Power Calculus(迭代深搜)
- UVa 1374 - Power Calculus (DFSID)
- UVA - 1374 Power Calculus 迭代深搜
- IDDFS--UVA - 1374 Power Calculus
- UVA 1374(p211)----Power Calculus
- UVA 1374 Power Calculus(IDA*)
- UVa 1374 - Power Calculus <IDA*算法>
- UVa 1374 - Power Calculus(IDA*)
- UVA 1374 Power Calculus(迭代深搜)
- UVa 1374:Power Calculus(IDA*)
- iOS动画——啥?AutoLayout还能做动画?
- activity_main cannot be resolved or is not a field
- bzoj 3240 [Noi2013]矩阵游戏
- hihocoder #1107 : Shortest Proper Prefix
- android应用程序和数据库文件绑定
- UVA 1374 Power Calculus
- std::any_of
- 520开通我的CSDN.NET账号
- [POJ 2182] Lost Cows · 树状数组
- 设计模式---单例模式(多线程下的单例模式)
- 自己实现字符串连接函数strcat
- Qt 生成一张图片
- 自己编写函数,实现库函数里的strcpy函数
- Java类集框架之LinkedList源码剖析