问题
https://vjudge.net/problem/UVA-10254
分析
汉诺塔问题有三个柱子:https://blog.csdn.net/qq_19446965/article/details/81591945
http://baijiahao.baidu.com/s?id=1651515518415910066&wfr=spider&for=pc
但是本题中有四个柱子,而且规则有所变化,每次可以先使用4个柱子,按照汉诺塔的移动方式将k个盘子放置在第四个柱子上,然后在移动剩下的n-k个盘子,使用三个柱子,按照规则将n-k个盘子放在第三根柱子上,最后将第四根柱子上的k个盘子移动到第三根柱子上。
这三步过程:
第一步:移动k个盘子,从第一根柱子到第四个,可以同时用4个柱子
第二步:移动n-k个盘子,从第一根柱子到第3个,可以同时用3个柱子
第二步:移动k个盘子,和第一步相反
three[i]=2^i-1代表三个柱子时的汉诺塔移动次数
four[i]代表四个柱子时的汉诺塔移动次数
题意是使用4个柱子移动n个盘子从1号柱子到3号柱子,就是four[n]
four[n]=min{four[k]*2+three[n-k]},0<=k<=n
然后转变成差分数列:https://blog.csdn.net/synapse7/article/details/12870091
具体如何转换没想通,只是通过观察结果看出来的
代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn=10000+5;
struct BigInt{
int num[10],len=0;
BigInt(int x=0){
// memset(num,0,sizeof(num));
len=0;
while(x){
num[len