Test instructions
Turtle Rabbit race, rabbit to run at a constant speed, turtle riding electric cars, there are several sites in the middle, the turtle can choose to charge or not charge, charging takes time, but the electric car is fast, no power when slow, ask the rabbit can win the turtle.
At first I used a variety of positions greedy, no. At that time, I had no idea what dynamic planning was, and that was the few algorithms on the Hdu 11 page.
If you know the DP then this problem can be done, for each site, the task is to arrive at the shortest time, its shortest time can be updated by the previous point: enumeration of the point of the last charging site to reach the shortest time of the previous site + in the middle does not charge the time spent, in which the shortest time as the optimal solution, Without considering the need to charge the site;
ans [i] = min (ans [j] + t [j, I]) (j∈[0, i-1]);
1#include <stdio.h>2 #defineMin (a) (a) < (b) a:b3 intl,n,c,t,vr,vt1,vt2,p[102];4 DoubleFintd)5 {6 if(D<=C)return(Double) d/vt1+T;7 Else return(Double) c/vt1+ (Double) (D-C)/vt2+T;8 }9 intMain () {Ten while(SCANF ("%d%d%d%d%d%d%d", &L,&N,&C,&T,&VR,&VT1,&VT2)! =EOF) { One Doubleans[102]; A inti,j; - for(i=1; i<=n;i++) scanf ("%d",&p[i]); -p[n+1]=L; the for(i=1; i<=n+1; i++){ -Ans[i]=f (P[i])-T; - for(j=1; j<i;j++) Ans[i]=min (Ans[i], (Ans[j]+f (p[i]-P[j] )); - } + if(ans[n+1]> (Double) L/VR) printf ("Good job,rabbit!\n"); - Elseprintf"What a pity rabbit!\n"); + } A return 0; at}
View Code
HDU 2059 DP