96. 奇怪的汉诺塔

https://www.acwing.com/problem/content/description/98/

假设有A,B,C,D四个,在A上有n个。要移动到D上

在4塔的情况下 先移动i个到B上,在移动剩下的n - i个到D上(此时是在3塔的情况下)

#include <bits/stdc++.h>
#define int long long
using namespace std;
int f[15],d[15];
signed main(){
   // freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    d[1] = 1;
    for(int i = 2; i <= 12; i++)
        d[i] = 1 + d[i - 1] * 2;
    memset(f,0x3f, sizeof(f));
    f[1] = 1;
    for(int i = 1; i <= 12; i++){
        for(int j = 0; j < i; j++)
            f[i] = min(f[i],f[j] * 2 + d[i - j]);
    }
    for(int i = 1; i <= 12; i++)
        cout << f[i] << endl;
    return 0;
}

 

posted @ 2020-03-27 18:25  Hazelxcf  阅读(164)  评论(0编辑  收藏  举报