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