hdu 2059 龟兔赛跑 (DP)

点击打开链接

dp
#include <stdio.h>
#include <string.h>
const double MAX = 999999999.0;
double dp[105];
int main()
{
    int i,j,n;
    double L,c,t,vr,vh,vl,len;   
    double temp,min;
    double a[105];   
    while(scanf("%lf",&L)!=EOF)
		
    {
		
        scanf("%d %lf %lf", &n, &c, &t);
		
        scanf("%lf %lf %lf", &vr, &vh, &vl);
		
        for(i=1;i<=n;i++)
			
            scanf("%lf", &a[i]);
		
        a[0]=0.0; a[n+1]=L;
		
        dp[0]=0.0;
		
        for( i=1; i<=n+1; i++)
			
        {
			
            min = MAX;
			
            for( j=0; j<i; j++)
				
            {
				
                len = a[i] - a[j];
				
                temp = len > c ? (c/vh+(len-c)/vl) : (len/vh);
				
                if(j)
					
                    temp += t;
				
                if(min > temp + dp[j])
					
                    min = temp + dp[j];
				
            }
			
            dp[i]=min;
			
        }
		
        printf("%s\n", dp[n+1] < (1.0*L)/vr ? "What a pity rabbit!" : "Good job,rabbit!" );
		
    }
	
    return 0;
	
}


你可能感兴趣的:(hdu 2059 龟兔赛跑 (DP))