汉诺塔IV---hdu2077

时间:2023-03-09 03:37:54
汉诺塔IV---hdu2077

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2077

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define N 25 int main()
{
int a[N]={0, 2};///汉诺塔三的规律,把最左边的移动到最右边的规律;
int b[N]={0, 1};///把最左边的移动到中间的规律;
int c[N]={0, 2};///本题规律; int i; for(i=2; i<21; i++)
a[i] = 3*a[i-1]+2;
for(i=2; i<21; i++)
b[i] = a[i-1]+1+b[i-1];
for(i=2; i<21; i++)
c[i] = 2*b[i-1]+2; int T, n; scanf("%d", &T); while(T--)
{
scanf("%d", &n);
printf("%d\n", c[n]);
}
return 0;
}