Hdu 2059 Tortoise and rabbit race (DP)

Source: Internet
Author: User
Tags cmath

Hdu 2059 Tortoise and rabbit race (DP)

 

It is not clear that the remaining power of electric vehicles cannot be used, and each time it is full.

 

Question Analysis:

For dynamic planning problems, you can perform DP on the site, plus a total of n + 2 sites at the start and end points. The start point indicates that the site is 0, and dp [n + 1] indicates the optimal time of the tortoise, that is, the shortest time, the dynamic conversion equation is: dp [I] = min (dp [I], dp [j] + t1); t1: the optimal (minimum) time from j to I.

 

AC code:

 

/*** @ Xiaoran * DP. The question is unclear and the remaining energy cannot be used * dp [I] = min (dp [I], dp [j] + cost ), cost: time from j --> I */# include
 
  
# Include
  
   
# Include
   # Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include
           
             # Define LL long longusing namespace std; const double DOB_MAX = 1000000.0; int path [110]; double dp [110]; int main () {int l, n, c, t, vr, vt1, vt2; while (scanf (% d, & l) = 1) {scanf (% d, & n, & c, & t ); scanf (% d, & vr, & vt1, & vt2); for (int I = 1; I <= n; I ++) {scanf (% d, & path [I]);} path [n + 1] = l; dp [0] = 0; double t1, t2; for (int I = 1; I <= n + 1; I ++) {dp [I] = DOB_MAX; for (int j = 0; j
            
              = Len) t1 = len * 1.0/vt1; // else t1 = c * 1.0/vt1 + (len-c) * 1.0/vt2; // use an electric car to drive c, and the remaining pedal if (j) t1 + = t; // calculate the fuel time. // 2. Do not refuel t2 = len * 1.0/vt2; t1 = min (t1, t2); // minimum cost from I to j dp [I] = min (dp [I], dp [j] + t1 );}} if (dp [n + 1]
             
              

 

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.