7
7
2015
0

XJOI 1425 楼梯

#include <iostream>
#include <climits>
using namespace std;

long long h[51],b[51]={1};
int n,f[51];

int main()
{
	cin>>n;
	for (int i=1;i<=n;++i){
		cin>>h[i];
		b[i]=b[i-1]<<1;
	}
	for (int i=2;i<=n;++i){
		f[i]=INT_MAX/3;
		for (int j=1;j<i;++j)
			for (int k=j;k>0;--k)
				if (b[j-k]+h[k]>=h[i])
					f[i]=min(f[j]+j-k+1,f[i]);
		if (f[i]==INT_MAX/3){
			cout<<-1;
			return 0;
		}
		//cout<<i<<'='<<f[i]<<endl;
	}
	cout<<f[n];
	return 0;
}
Category: 题解 | Tags: XJOI 动规 | Read Count: 214

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com