uva 1374 Power Calculus
来源:互联网 发布:linux应用放到哪里 编辑:程序博客网 时间:2024/06/08 07:01
//// main.cpp// uva 1374 - Power Calculus//// Created by XD on 15/7/29.// Copyright (c) 2015年 XD. All rights reserved.//#include <iostream>#include <string>#include <queue>#include <stack>#include <stdio.h>#include <stdlib.h>#include <math.h>#include<vector>#include <string.h>#include <string>#include <algorithm>#include <set>#include <map>#include <cstdio>using namespace std ;int num[1010] = {0,1,2,2,3,3,4,3,4,4,5,4,5,5,5,4,5,5,6,5,6,6,6,5,6,6,6,6,7,6,6,5,6,6,7,6,7,7,7,6,7,7,7,7,7,7,7,6,7,7,7,7,8,7,8,7,8,8,8,7,8,7,7,6,7,7,8,7,8,8,8,7,8,8,8,8,8,8,8,7,8,8,8,8,8,8,9,8,9,8,9,8,8,8,8,7,8,8,8,8,9,8,9,8,9,9,9,8,9,9,9,8,9,9,9,9,9,9,9,8,9,9,9,8,9,8,8,7,8,8,9,8,9,9,9,8,9,9,9,9,9,9,9,8,9,9,9,9,9,9,10,9,9,9,9,9,9,9,9,8,9,9,9,9,9,9,10,9,10,9,10,9,10,10,10,9,10,10,10,9,10,10,10,9,10,9,10,9,9,9,9,8,9,9,9,9,10,9,10,9,10,10,10,9,10,10,10,9,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,9,10,10,10,9,10,9,9,8,9,9,10,9,10,10,10,9,10,10,11,10,11,10,10,9,10,10,11,10,11,10,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,11,10,10,10,11,10,11,11,11,10,11,10,11,10,11,10,11,10,11,10,10,10,10,10,10,9,10,10,10,10,10,10,11,10,11,10,11,10,11,11,11,10,11,11,11,10,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,10,11,11,11,10,11,10,11,10,10,10,10,9,10,10,10,10,11,10,11,10,11,11,11,10,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,12,11,11,11,12,11,12,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,12,11,12,11,11,10,11,11,12,11,12,11,11,10,11,11,11,10,11,10,10,9,10,10,11,10,11,11,11,10,11,11,12,11,12,11,11,10,11,11,12,11,12,12,11,11,12,12,12,11,12,11,11,10,11,11,12,11,12,12,12,11,11,12,12,11,12,11,12,11,11,11,12,11,12,11,11,11,12,11,11,11,11,11,11,10,11,11,11,11,11,11,12,11,11,11,12,11,12,12,12,11,12,11,12,11,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,11,12,11,12,11,12,11,11,11,11,11,11,10,11,11,11,11,11,11,12,11,12,11,12,11,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,11,12,12,12,11,12,11,12,11,11,11,11,10,11,11,11,11,12,11,12,11,12,12,12,11,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,13,12,12,12,12,11,12,12,12,12,13,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,12,12,12,13,12,13,12,12,12,13,12,12,12,12,12,12,11,12,12,12,12,12,12,13,12,12,12,13,12,13,12,12,12,13,12,13,12,13,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,13,12,13,12,13,12,13,12,13,12,13,12,13,12,13,13,13,12,13,13,13,12,13,12,13,12,13,13,13,12,13,13,13,12,13,12,13,12,12,12,13,12,13,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,13,12,13,12,12,12,12,12,13,12,13,13,13,12,13,13,13,12,13,12,12,11,12,12,13,12,13,13,13,12} ;int maxd ;int path[1010] ;int n ;int a[20] ;int containX(int x,int len){ for (int i = 0; i <= len; i++) { if (path[i] == x) { return 1 ; } } return 0 ;}bool dfs(int step , int x){ if (x == n ) { return true ; } if (step== maxd) { return false ; } int tm = 0; for (int i = 0; i <=step ; i++) { tm = tm > path[i] ? tm : path[i] ; } if (tm * a[maxd - step] < n ) { return false ; } for (int i = step; i >=0 ; i--) { for (int j = i; j >=0; j--) { int t = path[i] + path[j] ; if (t * (a[maxd -step]) < n ) { continue ; } if (!containX(t,step)) { path[step+1] = t ; if(dfs(step+1, t)) { return true ; }; } t = path[i] - path[j] ; if (t > 0 && !containX(t, step)) { path[step+1] = t ; if( dfs(step+1, t)) return true ; } } } return false ;}int main() { a[1] = 2 ; for (int i =2; i < 20 ; i++) { a[i] = 2*a[i-1] ; } while (scanf("%d" , &n)==1 && n!= 0) { printf("%d\n" , num[n-1]) ;// for(int t = 900 ;t < 1001 ;t++)// {// n=t ;// // for (maxd = 1; maxd < 20; maxd++) {// // path[0] = 1 ;// if (dfs(0 , 1)) {// printf("%d," , 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*)
- the first time to write a web page
- PHP批量导出导入CSV文件实现原码
- 你需要知道的三个 CSS 技巧
- 纯粹的 K12 精髓:从马列主义角度分析如何教孩子看图写话
- Arcgis for android Error inflating class com.esri.android.map.MapView
- uva 1374 Power Calculus
- 卸载win10应用
- sizeof总结
- quartz及集群
- css学习心得
- 很高兴的通知大家微信PC版支持公众平台支持oauth2身份认证了
- 《一起学》系列2:C++面向对象
- 从1开始学ios开发
- 解决:Activity not started, its current task has been brought to the front