hdu 1207 汉诺塔II 递推

#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;

int main()
{
    ll a[70],t;
    int i,j,n;
    a[1]=1;
    a[2]=3;
    a[3]=5;
    for(i=4;i<=64;i++)
    {
        t=0xfffffff;
        for(j=1;j<=i/2;j++)
        {
           if(t>2*a[i-j]+pow(2.0,j)-1) t=2*a[i-j]+pow(2.0,j)-1;
        }
        a[i]=t;
    }
    while(~scanf("%d",&n))
    {
        printf("%lld\n",a[n]);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

posted @ 2015-09-10 11:29  xryz  阅读(88)  评论(0编辑  收藏  举报