HDU ACM 2059 Turtle and Rabbit race--Dynamic planning

Source: Internet
Author: User

Analysis: Dynamic planning, it is important to note that the current state needs to be considered together with all previous states, pay attention to the processing of floating-point numbers, but also WA once.

#include <iostream>using namespace Std;int l,n,c,t,vr,vt1,vt2;int a[105];d ouble dp[105];d ouble min_time_ij (int i _0,int j_0) {if (j_0-i_0>c) return c*1.0f/vt1+ (j_0-i_0-c) *1.0f/vt2;elsereturn (J_0-I_0) *1.0f/vt1;} int main () {int i,j;double min,value;while (cin>>l) {CIN>>N>>C>>T;CIN>>VR>>VT1 >>vt2;for (i=1;i<=n;i++) cin>>a[i];a[0]=0;a[n+1]=l;            Final distance as end Dp[0];for (i=1;i<=n+1;i++) {min=1000000;for (j=0;j<i;j++) {if (j==0)         //first electric vehicle has electricity value=dp[j]+min_ Time_ij (A[j],a[i]); Elsevalue=dp[j]+min_time_ij (A[j],a[i]) +t;  The first J station is charged directly to I. Min=min<value?min:value;} Dp[i]=min;} if (DP[N+1]<L*1.0F/VR) cout<< "What a pity rabbit!" <<endl;elsecout<< "Good job,rabbit!" <<endl;} return 0;}


HDU ACM 2059 Turtle and Rabbit race--Dynamic planning

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.