题目

题目

 


 

分析

IDA*大法好,抄了lrj代码。

 


 

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxans=14; int n,a[maxans+1]; bool dfs(int d,int maxd)
{
if(a[d] == n) return true;
if(d == maxd) return false; int maxv=a[0];
for(int i=1; i<=d; i++) maxv=max(maxv, a[i]);
if( (maxv << (maxd-d)) < n) return false; for(int i=d; i>=0; i--)
{
a[d+1]=a[d]+a[i];
if(dfs(d+1 , maxd)) return true;
a[d+1] = a[d] - a[i];
if(dfs(d+1 , maxd)) return true;
}
return false;
} int solve(int n)
{
if(n==1) return 0;
a[0]=1;
for(int maxd=1; maxd < maxans; maxd++)
if(dfs(0,maxd)) return maxd;
return maxans;
} int main()
{
while( scanf("%d",&n)==1 && n!=0)
printf("%d\n",solve(n));
return 0;
}

【UVa】1374 Power Calculus(IDA*)的更多相关文章

  1. UVa 1374 Power Calculus (IDA*或都打表)

    题意:给定一个数n,让你求从1至少要做多少次乘除才可以从 x 得到 xn. 析:首先这个是幂级的,次数不会很多,所以可以考虑IDA*算法,这个算法并不难,难在找乐观函数h(x), 这个题乐观函数可以是 ...

  2. 【Uva11212】 Editing a Book(IDA*)

    [题意] 有n个数字的全排列,每次可以剪切一段粘贴到某个位置.问最后变成升序最少多少步. 如"{2,4,1,5,3,6}要2步 {3,4,5,1,2}只要一步 [分析] 迭代深搜真的AC了也 ...

  3. 【UVa】Partitioning by Palindromes(dp)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=27&page=sh ...

  4. 【UVa】439 Knight Moves(dfs)

    题目 题目     分析 没有估价函数的IDA......     代码 #include <cstdio> #include <cstring> #include <a ...

  5. 【UVa】1600 Patrol Robot(dfs)

    题目 题目     分析 bfs可以搞,但是我还是喜欢dfs,要记忆化不然会T     代码 #include <cstdio> #include <cstring> #inc ...

  6. 【UVA】1596 Bug Hunt(模拟)

    题目 题目     分析 算是个模拟吧     代码 #include <bits/stdc++.h> using namespace std; map<int,int> a[ ...

  7. 【UVA】10763 Foreign Exchange(map)

    题目 题目     分析 没什么好说的,字符串拼接一下再放进map.其实可以直接开俩数组排序后对比一下,但是我还是想熟悉熟悉map用法. 呃400ms,有点慢.     代码 #include < ...

  8. 【题解】UVA10298 Power String(KMP)

    UVA10298:https://www.luogu.org/problemnew/show/UVA10298 思路 设P[x]数组为 前x个字符的最大前缀长度等于后缀字串 由P数组的定义我们可以知道 ...

  9. 【Luogu】P2324骑士精神(IDA*)

    题目链接 当guess>limit-deep的时候return就好了. guess是估价函数,值为不在自己地盘上的骑士个数.limit是本次迭代阈值.deep是已经走了多少步. 这个优化是显然的 ...

随机推荐

  1. LINUX系统下的数据库的管理

    环境:配置好IP和YUM源  一.数据库的安装及密码的修改 [1]yum  install  mariadb-server  -y       ##安装mariadb数据库 [2]systemctl  ...

  2. 熟悉linux命令

    <鸟哥的linux私房菜>这本书终于看到了敲命令行这块了,有点小激动,打开虚拟机,开始~~~敲!!! 登录界面,用户名密码~~~ 登录成功,下面开始熟悉一下,linux的常见命令了: li ...

  3. select2如何设置默认空值

    1.问题背景 select2搜索下拉框,当满足某种条件时,让它默认选中空值 2.问题原因 <!DOCTYPE html> <html> <head> <met ...

  4. awk结合正则匹配

    利用awk分析data.csv中label列各取值的分布. 在终端执行head data.csv查看数据: name,business,label,label_name 沧州光松房屋拆迁有限公司,旧房 ...

  5. [pandas] SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

    转载自https://blog.csdn.net/blackyuanc/article/details/77892784 问题场景:       在读取CSV文件后,在新增一个特征列并根据已有特征修改 ...

  6. 基于 od 窗口的anti

    虽然 odadvance 这类的插件 , 使用驱动将 od 的窗口 进行 隐藏,使用enumwindow ,无法枚举到od的窗口, 但是依然可以 使用r3 的方法 , 对od 窗口检测 之后可以使用 ...

  7. 解决 git 错误 error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 11

    环境 Windows 7 . git push 时出现错误,无法提交代码到远程仓库. Counting objects: , done. Delta compression using up to t ...

  8. mysql 关联左表不存在数据 并 根据身份证计算查找大于65岁以上老人

    --- //查找左边不存在数据,不能用 = '' SELECT m.uid FROM es_members m LEFT JOIN es_user_self_care_assessment u ON ...

  9. 转载——关于bp神经网络

    一.BP神经网络的概念     BP神经网络是一种多层的前馈神经网络,其主要的特点是:信号是前向传播的,而误差是反向传播的.具体来说,对于如下的只含一个隐层的神经网络模型: (三层BP神经网络模型) ...

  10. pyqtree

    pyqtree module API Documentation Classes class Index The top spatial index to be created by the user ...