HDU 2059 DP

Source: Internet
Author: User

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&LT;=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", &AMP;L,&AMP;N,&AMP;C,&AMP;T,&AMP;VR,&AMP;VT1,&AMP;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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.