poj1958Strange Towers of Hanoi
2014-11-16 22:13
337 查看
/********************** * Author:fisty * Data:2014-11-16 * poj1958 * 动态规划 * *******************/ #include <cstdio> #include <cstring> #include <math.h> #include <algorithm> using namespace std; #define INF 0x3f3f3f3f int table[15] = {0, 1, 3, 5}; int hanoi(int j, int i){ int cost = 0; cost += table[i]*2; cost += pow(2, j)-1; return cost; } int main(){ int cost; for(int i = 1;i <= 12; i++){ if(i > 3){ table[i] = INF; for(int j = 1; j < i; j++){ //枚举先把j个移到一个柱子上再把剩下的移到最终柱子 cost = hanoi(j, i-j); table[i] = min(cost, table[i]); } } printf("%d\n", table[i]); } return 0; }
相关文章推荐
- poj 1958 Strange Towers of Hanoi(递推)
- poj 1920 Towers of Hanoi
- 汉诺塔(Towers of Hanoi)问题
- poj 1958 Strange Towers of Hanoi
- SGU 202. The Towers of Hanoi Revisited
- poj 1958 Strange Towers of Hanoi
- poj 1958 Strange Towers of Hanoi
- URAL - 2029 Towers of Hanoi Strike Back
- POJ 1958 Strange Towers of Hanoi [dp]
- A Brief Summary of Towers of Hanoi Puzzle
- UVa 254 - Towers of Hanoi 解题报告(递归)
- F - Towers of Hanoi Strike Back-汉诺塔问题
- poj1920 Towers of Hanoi
- 【poj1958】Strange Towers of Hanoi
- POJ 1958 Strange Towers of Hanoi (线性dp 推公式)
- c/c++ 算法之汉诺塔(河内之塔(Towers of Hanoi))
- poj 1920 Towers of Hanoi
- poj 1958 Strange Towers of Hanoi
- POJ 1920 Towers of Hanoi 笔记
- ural 2029 Towers of Hanoi Strike Back (数学找规律)