HDU-1207 汉诺塔II
基础汉诺塔思路
acwing题解
b站视频
#include<iostream>
#include<algorithm>
#include<cstring>#define ull unsigned long long
using namespace std;const int N = 100;ull d[N],f[N];int main()
{
d[1] = 1;for(int i=2;i<=N;i++)d[i] = 1 + 2*d[i-1];memset(f,0x3f,sizeof(f));f[0] = 0;for(int i=1;i<=N;i++)for(int j=0;j<i;j++)f[i] = min(f[i],f[j]*2+d[i-j]);int n;while(cin>>n){
cout<<f[n]<<endl;}return 0;
}