n個盤子的漢諾塔問題的最少移動次數是2^n-1,即在移動過程中會產生2^n個系列。由于發生錯移產生的系列就增加了,這種錯誤是放錯了柱子,并不會把大盤放到小盤上,即各柱子從下往上的大小仍保持如下關系:n=m+p+qa1>a2>...>amb1>b2>...>bpc1>c2>...>cq計算所有會產生的系列總數。
包含多組數據,首先輸入T,表示有T組數據.每個數據一行,是盤子的數目N<30。
對于每組數據,輸出移動過程中所有會產生的系列總數。
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;}
新聞熱點
疑難解答