AcWing 96. 奇怪的汉诺塔
原题链接
简单
作者:
稗官
,
2024-09-25 16:01:20
,
所有人可见
,
阅读 2
#include <iostream>
using namespace std;
#include <cstring>
#include <vector>
const static int N = 20;
int three[N], four[N];
int main()
{
// 初始化
memset(four, 0x3f, sizeof four);
three[1] = four[1] = 1;
// 预处理,先计算出三塔结果
for(int i = 1; i <= N; ++i) three[i] = three[i - 1] + 1 + three[i - 1];
for(int i = 1; i <= 12; ++i)
{
for(int j = 1; j <= i; ++j)
{
// 在三塔和四塔问题间切换
four[i] = min(four[i], four[j] + three[i - j] + four[j]);
}
cout << four[i] << endl;
}
}