思路:

先求出三柱汉诺塔:d【i】,
之后:f[i]=min(f[i],2*f[h]+d[i-h]);

#include<bits/stdc++.h>
using namespace std;
int main() {
	int d[30],f[30];
	d[1]=1;
	for(int i=2; i<=15; i++) {
		d[i]=2*d[i-1]+1;
	}
	memset(f,0x3f,sizeof f);
	f[0]=0;
	for(int i=1; i<=15; i++) {
		for(int h=0; h<i; h++) {
			f[i]=min(f[i],2*f[h]+d[i-h]);
		}
	}
	for(int i=1; i<=15; i++) {
		cout<<f[i]<<" ";
	}
	return 0;
}
 posted on 2019-07-08 14:13  谁是凶手1703  阅读(76)  评论(0)    收藏  举报