Sicily 1264. Atomic car race Dynamic Planning

Source: Internet
Author: User
// This question was made for one night // a very simple DP water question. At first it timed out and then wa again after optimization. The result showed that the output accuracy was insufficient, at least four digits after the decimal point must be output. // preprocessing is required first, otherwise, there will be a lot of repeated computations in the DP process. // set DP [I] to complete a [1] +... + minimum time of a [I], after cost [I] [J] is the slave station I tire replacement, time required for arrival J // DP [I] = min (DP [k] + cost [k] [I] + B ), 0 <k <I/dp [0] = 0; # include <iostream> # include <cstdio> using namespace STD; const int n = 105; const int M = 10005; const int INF = 1000000000; double DP [N]; double cost [N] [N]; double total [m]; int record [N]; int A [n]; int N, R; doubl E v, E, F, B; double CAL (INT X) {If (x> = r) return 1/(V-E * (X-R )); elsereturn 1/(V-f * (R-x);} int main () {A [0] = 0; int Maxx, mini; while (CIN> N & N) {Maxx =-INF; For (INT I = 1; I <= N; I ++) {CIN> A [I]; DP [I] = inf; Maxx = max (Maxx, a [I]);} CIN> B; cin> r> V> E> F; Total [0] = CAL (0); For (INT I = 1; I <= Maxx; I ++) total [I] = total [I-1] + CAL (I); For (INT I = 0; I <= N; I ++) for (Int J = I + 1; j <= N; J ++) cost [I] [J] = total [A [J]-A [I]-1]; DP [0] = 0; record [0] = 0; For (INT I = 1; I <= N; I ++) for (int K = 0; k <I; k ++) if (K! = 0) DP [I] = min (DP [I], DP [k] + cost [k] [I] + B ); elsedp [I] = min (DP [I], DP [k] + cost [k] [I]); printf ("%. 4lf \ n ", DP [N]);} return 0 ;}

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.