2011百度之星 复赛(下)第一题

// BDFS2_1.cpp : Defines the entry point for the console application.

//



#include "stdafx.h"

#include <iostream>

using namespace std;

#define MAX 1000005

#define min(x,y) ((x)<(y)?(x):(y))

#define INF 99999999

int h[MAX];

int n;

//bool couldJump[MAX][MAX];

int dp[MAX];//d第0点往j点跳

bool couldJump(int x,int y){

	

	if(y<=x)return false;

	for(int i=x+1;i<y;i++){

		if(h[i]>=h[x]&&h[i]>=h[y])return false;

	}

	

	if(y-x>h[x])return false;

	

	

	return true;

}

int main(int argc, char* argv[])

{

	freopen("i://input.txt","r",stdin);

	int i,j;

	

	scanf("%d",&n);

	for(i=0;i<n+1;i++)

		scanf("%d",h+i);



		dp[0]=0;

		for(j=1;j<=n;j++){

			

			dp[j]=INF;

		}

		for(i=1;i<=n;i++){

			

			for(int j=i-1;j>=0;j--){

				

				if(couldJump(j,i)){

					

					int ti = 0;

					if(h[j]<=h[i])ti=h[i]-h[j];

			

					if(dp[j]+ti<dp[i])

						dp[i]=dp[j]+ti;

			

				}

				

			}

			

		}

		printf("%d\n",dp[n]);

		return 0;

}

你可能感兴趣的:(百度)