hdu 2059 简单dp

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAX 107
#define INF 0xfffffffL

using namespace std;

int l,n,c,tt,v1,v2,v;
int p[MAX];
double dp[MAX];

int main ( )
{
	while ( ~scanf ( "%d" , &l ) )
	{
		scanf ( "%d%d%d" , &n , &c , &tt );
		scanf ( "%d%d%d" , &v , &v1 , &v2 );
		for ( int i = 1 ; i <= n ; i++ ) scanf ( "%d" , &p[i] );
		p[0] = 0;
		p[n+1] = l;
		for ( int i = 1 ; i <= n+1 ; i++ ) dp[i] = INF;
		dp[0] = -tt;
		for ( int i = 1 ; i <= n+1 ; i++ )
			for ( int j = 0 ; j < i ; j++ )
			{
				int len = p[i] - p[j];
				double t = tt;
				if ( len >= c ) 
				{
					t += c*1.0/(v1*1.0);
					t += (len-c)*1.0/(v2*1.0);
				}
				else t += len*1.0/(v1*1.0);
				dp[i] = min ( dp[i] , dp[j] + t );
			}
		double tr = l*1.0/(v*1.0);
       // cout << tr << " " << dp[n+1] << endl;
		if ( tr > dp[n+1] ) puts ( "What a pity rabbit!" );
	   	else puts ( "Good job,rabbit!" );	
	}
}

你可能感兴趣的:(C++,动态规划)