/**********************
* 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;
}
poj1958Strange Towers of Hanoi
最新推荐文章于 2019-01-21 19:44:00 发布