说是递推,其实也算是个DP吧。

就是4塔的汉诺塔问题。

考虑三塔:先从a挪n-1个到b,把最大的挪到c,然后再把n-1个从b挪到c,所以是

f[i] = 2 * f[i-1] + 1;

那么4塔类似:

先在4塔模式下挪j个到b,然后在三塔模式下挪n-j个到d,然后再在4塔模式下挪j个到d。

故状态转移方程:

d[i] = min(2 * d[j] + f[n-j]) ,其中1 <= j < n

初始条件:f[n]与d[1] = 1;

然后就没有然后了。

 #include <cstdio>
#include <algorithm>
using namespace std;
const int N = ,INF=0x7f7f7f7f;
int f[N],d[N];
int main()
{
f[]=d[]=;
f[]=d[]=;
for(int i=;i<=;i++) {
f[i]=*f[i-]+;
}
for(int i=;i<=;i++)
{
int temp=INF;
for(int j=;j<i;j++)
temp=min(temp,*d[j]+f[i-j]);
d[i]=temp;
}
for(int i=;i<=;i++)
printf("%d\n",d[i]); return ;
}

AC代码

poj1958 strange towers of hanoi的更多相关文章

  1. POJ-1958 Strange Towers of Hanoi(线性动规)

    Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2677 Accepted: 17 ...

  2. POJ1958 Strange Towers of Hanoi [递推]

    题目传送门 Strange Towers of Hanoi Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3117   Ac ...

  3. poj1958——Strange Towers of Hanoi

    The teacher points to the blackboard (Fig. 4) and says: "So here is the problem: There are thre ...

  4. POJ 1958 Strange Towers of Hanoi 解题报告

    Strange Towers of Hanoi 大体意思是要求\(n\)盘4的的hanoi tower问题. 总所周知,\(n\)盘3塔有递推公式\(d[i]=dp[i-1]*2+1\) 令\(f[i ...

  5. POJ 1958 Strange Towers of Hanoi

    Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3784 Accepted: 23 ...

  6. POJ1958:Strange Towers of Hanoi

    我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:http://poj.org/problem?id=1958 题目要我们求四柱 ...

  7. [POJ1958][Strange Tower of Hanoi]

    题目描述 求解 \(n\) 个盘子 \(4\) 座塔的 Hanoi 问题最少需要多少步 问题分析 考虑 \(3\) 座塔的 Hanoi 问题,记 \(f[i]\) 表示最少需要多少步, 则 \(f[i ...

  8. Strange Towers of Hanoi

    题目链接:http://sfxb.openjudge.cn/dongtaiguihua/E/ 题目描述:4个柱子的汉诺塔,求盘子个数n从1到12时,从A移到D所需的最大次数.限制条件和三个柱子的汉诺塔 ...

  9. Strange Towers of Hanoi POJ - 1958(递推)

    题意:就是让你求出4个塔的汉诺塔的最小移动步数,(1 <= n <= 12) 那么我们知道3个塔的汉诺塔问题的解为:d[n] = 2*d[n-1] + 1 ,可以解释为把n-1个圆盘移动到 ...

随机推荐

  1. [转帖]nginx服务器安装及配置文件详解

    nginx服务器安装及配置文件详解 http://seanlook.com/2015/05/17/nginx-install-and-config/  发表于 2015-05-17 |  更新于: 2 ...

  2. bootstrap.css.map 404

    删除bootstrap.css的最后一行即可: /*# sourceMappingURL=bootstrap.css.map */ English: from bootstrap-theme.css  ...

  3. git format-patch制作内核补丁

    git init git add ./ git commit 之后修改代码 修改代码后执行 git add ./ git commit 执行完成后执行git log查询commit 的id 执行git ...

  4. Java并发编程之ThreadGroup

    ThreadGroup是Java提供的一种对线程进行分组管理的手段,可以对所有线程以组为单位进行操作,如设置优先级.守护线程等. 线程组也有父子的概念,如下图: 线程组的创建 public class ...

  5. css & clearfix & clear-fixed

    css & clearfix & clear-fixed https://zzk.cnblogs.com/my/s/blogpost-p?Keywords=clearfix .grou ...

  6. 一、ABP框架框架摘要

    ABP框架几点说明: 一.什么是ABP ABP是一个建立在最新的ASP.NET的MVC和Web API技术的应用框架.它可以很容易地使用依赖注入.日志记录.验证.异常处理.本地化等,也使用流行的框架和 ...

  7. 规范化Normalization

    一.批规范化 Batch Normalization 转自: http://blog.csdn.net/hjimce/article/details/50866313    https://zhuan ...

  8. How to enable flash on Chromium

    sudo apt install chromium-browser pepperflashplugin-nonfree

  9. Membership 介绍

    ASP.NET成员资格为您提供了验证和存储用户凭据的内置方式.因此,ASP.NET成员可以帮助您管理网站中的用户身份验证.您可以使用ASP.NET表单身份验证使用ASP.NET成员身份,方法是使用AS ...

  10. WEB请求处理

    https://blog.csdn.net/bpingchang/article/details/51328941