n個盤子的漢諾塔問題的最少移動次數(shù)是2^n-1,即在移動過程中會產(chǎn)生2^n個系列。由于發(fā)生錯移產(chǎn)生的系列就增加了,這種錯誤是放錯了柱子,并不會把大盤放到小盤上,即各柱子從下往上的大小仍保持如下關系:n=m+p+qa1>a2>...>amb1>b2>...>bpc1>c2>...>cq計算所有會產(chǎn)生的系列總數(shù)。
包含多組數(shù)據(jù),首先輸入T,表示有T組數(shù)據(jù).每個數(shù)據(jù)一行,是盤子的數(shù)目N<30。
對于每組數(shù)據(jù),輸出移動過程中所有會產(chǎn)生的系列總數(shù)。
31329Example Output
32768630377364883Hint
Author
Answer: #include<stdio.h>#include<stdlib.h>#include<math.h>int main(){ int i,n; long long int t; scanf("%d",&n); while(n--) { scanf("%d",&i); t=pow(3,i); printf("%lld/n",t); } return 0;}
新聞熱點
疑難解答