Problem Description
http://acm.hdu.edu.cn/showproblem.php?pid=1494
running Kart is a popular online casual game where you can experience driving pleasure in this virtual world. The special point of this game is that you can drift to get a
The accelerator card allows you to increase your speed in a limited amount of time with this accelerator card. To make the problem simple, let's say that a track is divided into L segments, and gives you the usual time-consuming AI for each track and time-consuming bi with an accelerator card. The accelerator card acquisition mechanism is: in the case of normal driving, each through 1 segments, you can get 20% of the energy (N2O). When the energy is full, an accelerator card (at the same time 0) is obtained. The accelerator card can store up to 2, which means that when you have 2 accelerator cards and the energy is full again, the energy is cleared 0 but An accelerator card can only maintain a track and the game starts without an accelerator card.
The question is, what is the minimum time to run n laps? InputEach group of input data has 3 rows, the first row has 2 integer l (0<l<100), N (0<n<100) respectively indicates that a lap track is divided into L segment and N-lap track, the next two lines have L integer AI and bi
(Ai > Bi).
Outputfor each set of input data, outputting an integer indicates the minimum time.
Sample Input
18 19 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 98 8 8 8 8 8 8 8 8 8 8 8 8 8 1 1 8 8
Sample Output
145 topic Analysis: Dynamic planning problems, I feel that when doing this problem, do not dwell on the question of time, not the future or the past, the computer is dealing with problems, can find the best is good, the explanation of the problem in the code has detailed comments. AC Code: /** * @xiaoran *DP; * Can be used dp[i] to indicate the minimum time in paragraph I, you can use J to indicate the number of energy slots, up to 15 states *dp[i][j]: At the time of paragraph I, J Energy tank full state of the minimum time, you can be sure the first time for the *dp[n][k]:n to represent the number of laps, k=[1,14], When it reaches 15, it will automatically clear zero, and will not get energy *dp[i][j]=min (Dp[i][j],dp[i-1][j-1]+a[i],dp[i-1][j+5]+b[i]) * Note: Dp[i][j] can be dp[i-1][j-1] Do not use the accelerator directly to exercise, *: Dp[i][j] can be directly exercised by using the accelerator card, the use of acceleration will reduce the 5 energy slots, * equivalent to use the next 5 energy slots, DP time should not have been entangled in the state of time, advance or delay * special, in j==10 time can by dp[i-1][14], because at this time there are 2 accelerator cards, when the full * Five energy slots will only clear 0 * for N Circle can be expressed as n*l segment */#include <iostream> #include <cstdio># include<map> #include <cstring> #include <string> #include <algorithm> #include <queue># include<vector> #include <stack> #include <cstdlib> #include <cctype> #include <cmath># Define LL long long#define inf 0x3f3f3f3fusing namespace Std;int a[10010],b[10010],dp[10010][16];int main () {int l,n; while (scanf ("%d%d", &l,&n) ==2) {for (int i=1;i<=l;i++) {scanf ("%d", &a[i]); for (int j=1;j<=n;j++) {a[i+j*l]=a[i]; }} for (int i=1;i<=l;i++) {scanf ("%d", &b[i]); for (int j=1;j<=n;j++) {b[i+j*l]=b[i]; }} memset (Dp,inf,sizeof (DP));//The minimum value is initialized to a relatively large value dp[0][0]=0; for (int i=1;i<=l*n;i++) {for (int j=0;j<15;j++) {if (j!=0) dp[i][j]=min (dp[i][j],dp[i-1][j-1 ]+a[i]); if (j<10) dp[i][j]=min (Dp[i][j],dp[i-1][j+5]+b[i]); if (j==10) dp[i][j]=min (Dp[i][j],dp[i-1][14]+a[i]); }} int res=dp[l*n][0]; for (int i=0;i<15;i++) {if (Res>dp[l*n][i]) {res=dp[l*n][i]; }} printf ("%d\n", res); } return 0;}
hdu1494 Run kart (Dynamic planning)