标签:des style class blog code http
hdu2059 龟兔赛跑 动态规划
题目描述:
100 3 20 5 5 8 2 10 40 60 100 3 60 5 5 8 2 10 40 60
Sample Output
Good job,rabbit! What a pity rabbit!解题思路:
1 #include <stdio.h> 2 3 int main() { 4 int l, n, c, t, vr, vt1, vt2, p[105], i, j; 5 double dp[105], tmp; 6 7 while(~scanf("%d", &l)) { 8 scanf("%d%d%d", &n, &c, &t); 9 scanf("%d%d%d", &vr, &vt1, &vt2); 10 for(i = 1; i <= n; i++) { 11 scanf("%d", &p[i]); 12 } 13 p[0] = 0; 14 p[n + 1] = l; 15 dp[0] = 0; 16 for(i = 1; i <= n + 1; i++) { 17 double min = 1000000000.0; 18 for(j = 0; j < i; j++) { 19 int len = p[i] - p[j]; 20 if(len < c) 21 tmp = len * 1.0 / vt1; 22 else 23 tmp = c * 1.0 / vt1 + (len - c) * 1.0 / vt2; 24 if(j != 0) 25 tmp += t; 26 if(min > dp[j] + tmp) 27 min = dp[j] + tmp; 28 } 29 dp[i] = min; 30 } 31 printf(dp[n + 1] > (l * 1.0 / vr) ? "Good job,rabbit!\n" : "What a pity rabbit!\n"); 32 } 33 return 0; 34 }
标签:des style class blog code http
原文地址:http://www.cnblogs.com/xiaoniunwp/p/3792251.html