On the Towers of Hanoi problem with multiple spare pegs
- 格式:pdf
- 大小:108.57 KB
- 文档页数:5
[1]POJ动态规划题目列表容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740(博弈), 1742, 1887, 1926(马尔科夫矩阵,求平衡), 1936,1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029,2039, 2063, 2081, 2082,2181, 2184, 2192, 2231, 2279, 2329, 2336, 2346, 2353,2355, 2356, 2385, 2392, 2424,不易: 1019,1037, 1080, 1112, 1141, 1170, 1192, 1239, 1655, 1695, 1707,1733(区间减法加并查集), 1737, 1837, 1850, 1920(加强版汉罗塔), 1934(全部最长公共子序列), 1937(计算几何), 1964(最大矩形面积,O(n)算法), 2138, 2151, 2161(烦,没写), 2178,推荐: 1015, 1635, 1636(挺好的), 1671, 1682, 1692(优化), 1704, 1717, 1722, 1726, 1732, 1770, 1821, 1853, 1949, 2019, 2127, 2176, 2228, 2287, 2342, 2374, 2378, 2384, 2411 状态 DP 树 DP 构造最优解四边形不等式单调队列1015 Jury Compromise1029 False coin1036 Gangsters1037 A decorative fence1038 Bugs Integrated, Inc.1042 Gone Fishing1050 To the Max1062 昂贵的聘礼1074 Parallel Expectations1080 Human Gene Functions1088 滑雪1093 Formatting Text1112 Team Them Up!1141 Brackets Sequence1143 Number Game1157 LITTLE SHOP OF FLOWERS 1159 Palindrome1160 Post Office1163 The Triangle1170 Shopping Offers1178 Camelot1179 Polygon1180 Batch Scheduling1185 炮兵阵地1187 陨石的秘密1189 钉子和小球1191 棋盘分割1192 最优连通子集1208 The Blocks Problem 1239 Increasing Sequences 1240 Pre-Post-erous!1276Cash Machine1293 Duty Free Shop1322 Chocolate1323Game Prediction1338 Ugly Numbers1390 Blocks1414 Life Line1432 Decoding Morse Sequences 1456 Supermarket1458 Common Subsequence1475 Pushing Boxes1485 Fast Food1505 Copying Books1513 Scheduling Lectures1579 Function Run Fun1609 Tiling Up Blocks1631 Bridging signals 2 分+DP NLOGN 1633 Gladiators 1635 Subway tree systems 1636 Prison rearrangement1644 To Bet or Not To Bet1649 Market Place1651 Multiplication Puzzle1655 Balancing Act1661 Help Jimmy1664 放苹果1671 Rhyme Schemes1682 Clans on the Three Gorges1690 (Your)((Term)((Project)))1691 Painting A Board1692 Crossed Matchings1695 Magazine Delivery1699 Best Sequence1704 Georgia and Bob1707 Sum of powers1712 Flying Stars1714 The Cave1717 Dominoes1718 River Crossing1722 SUBTRACT1726 Tango Tango Insurrection 1732 Phone numbers1733 Parity game1737 Connected Graph1740 A New Stone Game1742 Coins P1745 Divisibility1770 Special Experiment1771 Elevator Stopping Plan 1776 Task Sequences1821 Fence1837 Balance1848 Tree1850 Code1853 Cat1874 Trade on Verweggistan 1887 Testing the CATCHER 1889 Package Pricing1920 Towers of Hanoi1926 Pollution1934 Trip1936 All in All1937 Balanced Food1946 Cow Cycling1947 Rebuilding Roads1949 Chores1952 BUY LOW, BUY LOWER 1953 World Cup Noise1958 Strange Towers of Hanoi 1959 Darts1962 Corporative Network 1964 City Game1975 Median Weight Bead 1989 The Cow Lineup2018 Best Cow Fences2019 Cornfields2029 Get Many Persimmon Trees2033 Alphacode2039 To and Fro2047 Concert Hall Scheduling2063 Investment2081 Recaman's Sequence2082 Terrible Sets2084 Game of Connections2127 Greatest Common Increasing Subsequence 2138 Travel Games2151 Check the difficulty of problems2152 Fire2161 Chandelier2176 Folding2178 Heroes Of Might And Magic2181 Jumping Cows2184 Cow Exhibition2192 Zipper2193 Lenny's Lucky Lotto Lists2228 Naptime 2231 Moo Volume2279 Mr. Young's Picture Permutations2287 TianJi -- The Horse Racing 2288 Islands and Bridges2292 Optimal Keypad2329 Nearest number - 22336 Ferry Loading II2342 Anniversary party2346 Lucky tickets2353 Ministry2355 Railway tickets2356 Find a multiple2374 Fence Obstacle Course2378 Tree Cutting2384 Harder Sokoban Problem2385 Apple Catching2386 Lake Counting2392 Space Elevator2397 Spiderman2411 Mondriaan's Dream2414 Phylogenetic Trees Inherited 2424 Flo's Restaurant2430 Lazy Cows2915 Zuma3017 Cut the Sequence 3028 Shoot-out3124 The Bookcase3133 Manhattan Wiring 3345 Bribing FIPA3375 Network Connection 3420 Quad Tiling ?。
河內塔的遞歸實現與並非現實的河內塔THE HANOI-TOWER BY RECURSION AND THE UNREAL TOWERS OF HANOI位於印度北部,世界中心,有一貝拿勒斯聖廟,其中的三根石柱上串著64枚金盤。
婆羅門們,不分晝夜地在三根柱子間移動著這些金片,孜孜不倦~只為一個古老的傳言,即當所有盤子移動完畢,世界將於一聲霹靂中消滅,而梵塔、廟宇和眾生則將隨之同歸於盡。
而預有此言者就是上面這位,印度傳說中的創世之神—大梵天。
顯然這又是一個世界末日預言,其哲學理學思想之深邃不禁使後人產生無止地辯論與無盡的遐想。
時至今日,它已然成了一科人人樂於稱道的世界著名學問分支—梵天寺之塔問題(Tower of Brahma puzzle)。
河內塔,或音譯為漢諾塔,1結構如下圖。
不必細述。
1婆羅門所要做的是所要做的是將一根柱子上的所有盤片移動到另一根上,當然它有它的法則,看似易如反掌的事就是在這些法則下變得遙不可及。
法則:一次只能移動一個盤片;不能把小盤片置於大盤片上。
當然了,三根柱子我們都要用到。
原理剖析:區區64個盤片,移動多少步能完成呢?順著想不容易,不如我們逆過來思考。
我們看:以5塊盤片為例,想要把第5塊移動到C上。
1.先須把前4塊移動到B。
2.再把第5塊移到C。
3.最後重複移動前4塊的方法,把前4塊移到C。
如下圖。
則移動5塊的次數=2倍的移動4塊的次數+1次。
那麼推廣開來,移動n塊的次數=2倍的移動(n-1)塊的次數+1次。
據說,最早發明這個問題的人是法國數學家爱德华•卢卡斯。
從數學上我們來做下證明:其實也不是逆證,順推而已。
假設有n個盤片,移動的次數為f(n).如以上所述f(5)=2*f(4)+1;則f(n)=2*f(n-1)+1=2*[2*f(n-2)+1]+1-----------------------------------------------------------------展開 =2^2*f(n-2)+2^1+1……=2^(n-1)f(1)+2^(n-2)+2^(n-3)+...+2^1+1-------------------最後形式顯然,f(1)=1則 f(n)=2^(n-1)+{2^(n-2)[1-(1/2)^(n-1)]}/(1-1/2)=2^(n-1)+2^(n-1)-2^(n-1)*(1/2)^(n-1)=2^n-1完畢。
The tower of HanoiGiven three towers, or peg A, B and C. Three rings are piled in decreasing size on A, and the other pegs areempty. We want to move the rings from A to one of the other pegs. The rule is that rings are to be moved one at a time. but a larger ring may never be placed atop a smaller one.3-ring puzzleThis puzzle can be solved in seven steps:1. move the top ring from A to B2. move the top ring from A to C3. move the top ring from B to C4. move the top ring from A to B5. move the top ring from C to A6. move the top ring from C to B7. move the top ring from A to B1 move the smallest ring to the peg residing nextto it in clockwise order;2 make the only legal move possible that doesnot involve the smallest ringA time analysis shows that the number of single-ring moves it produces is precisely 2N-1Tibetan monks's gameThe original version of the puzzle had the same three pegs. and it involved 64 rings, moved by Tibetan monks. If the monks were to move one ring every five seconds. It would take them almost three trillion vears to get the job done.No wonder they believed the world would end before they managed to finish.。