Run KartTime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2514 Accepted Submission (s): 875
Problem description Run Kart is a popular online casual game, you can experience the fun of driving 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?
Input data for each set of 3 rows, the first row has 2 integer l (0<l<100), N (0<n<100) respectively, the circuit is divided into L-segment and N-lap track, the next two lines have an L integer AI and bi
(Ai > Bi).
Output for 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
145HintHint for the sample set of data, you can first run the first 14 paragraphs in normal circumstances, when you have 2 accelerator cards and 80% of the energy (N2O). Use 2 accelerator cards in paragraphs 15th and 16 You can get an accelerator card after the 17th track and use it on the 18th track.
A DP topic.
The note is the first code, using two-dimensional to record the state.
After reading the puzzle, we use time one dimension to do the scrolling array. Then make 20%no 1. A card to do 5. This is only a one-dimensional, relatively simple.
Write the state equation as required. Acceleration Time Time[cur][k]=min (Time[cur][k],time[cur^1][k+5]+b[j]); When not accelerating time[cur][k]=min (time[cur][k],time[cur^1][k-1]+a[j]);
Note that if you have two cards and you accumulate no when you have 80% no, you will not get more than one card. Time[cur][10]=min (Time[cur][10],time[cur^1][14]+a[j]);
#include <stdio.h> #include <iostream> #include <algorithm> #include <cmath> #include <map > #include <string>using namespace Std;int time[2][20]; One-dimensional scrolling array int a[110],b[110];int main () {int l,n;while (scanf ("%d%d", &l,&n)!=eof) {for (int i=0;i<=14;i++) { time[0][i]=99999999; }time[0][0]=0;for (int i=0;i<l;i++) cin>>a[i];for (int i=0;i<l;i++) cin>>b[i]; int cur=0; for (int i=0;i<n;i++) {for (int j=0;j<l;j++) {cur^=1;for (int k=0;k<=14;k++) time[cur][k]=99999999;/*for (int k= 0;k<=14;k++) {if (k%5==0) puts ("");p rintf ("%9d", Time[cur^1][k]);} Puts ("\ n"); */for (int k=0;k<=14;k++) {//acceleration bif (k<=9) time[cur][k]=min (Time[cur][k],time[cur^1][k+5]+b[j]);// General AIF (K!=0) time[cur][k]=min (Time[cur][k],time[cur^1][k-1]+a[j]); if (k==10)//time[cur][10]=min (Time[cur][10],time[cur^1][14]+a[j]);}}} int minn=99999999;for (int i=0;i<=14;i++) minn=min (Minn,time[cur][i]);p rintf ("%d\n", Minn);} return 0;} /*int time[2][5][10];//One-dimensional scrolling array two-dimensional records have several cards three-dimensional record how many noint a[110],b[110];//Elapsed Time int main () {int l,n;while (scanf ("%d%d", &l,&n)!=eof) {for (int. i=0;i<3;i++) {for (int j) =0;j<5;j++) {time[0][i][j]=99999999;}} time[0][0][0]=0;for (int i=0;i<l;i++) {scanf ("%d", a+i);} for (int i=0;i<l;i++) {scanf ("%d", b+i);} int cur=0;for (int i=0;i<n;i++)//quan{for (int j=0;j<l;j++)//duan{cur^=1;//current for (int k=0;k<3;k++) {for (int L) =0;l<5;l++) {//printf ("%8d", Time[cur^1][k][l]); time[cur][k][l]=99999999;} Puts ("");} Puts ("");//card acceleration Case//bfor (int k=0;k<2;k++) {for (int l=0;l<5;l++) {time[cur][k][l]=min (time[cur][k][l],time[ CUR^1][K+1][L]+B[J]); }}//without card//afor (int k=0;k<3;k++) {for (int l=0;l<5;l++) {if (l!=0)//Add Notime[cur][k][l]=min (Time[cur][k][l], TIME[CUR^1][K][L-1]+A[J]); else if (k!=0)//{time[cur][k][l]=min (Time[cur][k][l],time[cur^1][k-1][4]+a[j]);//Increase card if (k==2)//card more than 2 do not add card time[ Cur][k][l]=min (Time[cur][k][l],time[cur^1][k][4]+a[j]);}}}} int ans=99999999;for (int k=0;k<3;k++) {for (int l=0;l<5;l++) {ans=min (ans,time[cur][k][l]);}}printf ("%d\n", ans); }return 0;} *//*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*/
HDU 1494 run Go kart DP