Test instructions: A lap of the track into the L segment, each of the two cases, at a normal speed to obtain 20% of energy, with the speed of the accelerator card is accelerated, the accelerator card needs 100% of the energy to exchange. The accelerator card collects up to two cards. The shortest time to run through the M-ring.
Analysis:
DP problem or state is uncertain. Let's look at it together with the Rp. The RP is a one-dimensional, the problem is two-dimensional, but the starting point of determining the state is similar.
Quote a netizen's words, deepen understanding: "Because the track is divided into the L segment, it is easy to think of the first dimension of DP to indicate the current track in the section." Because the accelerator card to 100% energy to get a picture, and each walk a track and will get 20% of the energy, so we can be the energy trough is divided into segments, with 5 segments of the energy tank can be obtained an accelerator card, then the second Bellavita represents the current energy trough the number of words, it represents all the state. ”
DP[I][J] Indicates the shortest time, dp[i][j]=min (Dp[i-1][j-2]+a[i],dp[i-1][j+10]+b[i]) spent in the I-segment energy of J. Note that some special cases are considered separately, such as j=20 can be 18 or can be 28 transferred over
Code:
#include <iostream> #define INF 100000000007 using namespace Std;int l,m;long long Dp[10005][50],ans;int a[10005],b [10005];long Long min (long I,long long j) {return i<j?i:j;} void DP () {for (Int. i=1;i<=l*m;i++) for (int j=0;j<30;j+=2) dp[i][j]=inf;dp[1][2]=a[1];for (int i=2;i<=l*m ; i++) {for (int j=0;j<30;j+=2) {if (j>0&&j<20) dp[i][j]=min (Dp[i-1][j-2]+a[i],dp[i-1][j+10]+b[i]); if (j==0) dp[i][j]=dp[i-1][j+10]+b[i];if (j>20) dp[i][j]=dp[i-1][j-2]+a[i];if (j==20) dp[i][j]=min (dp[i-1][j-2]+a [I],dp[i-1][28]+a[i]);}}} int main () {while (cin>>l>>m) {for (int i=1;i<=l;i++) { cin>>a[i]; for (int j=1;j<=m;j++) a[i+l*j]=a[i];} for (int i=1;i<=l;i++) { cin>>b[i]; for (int j=1;j<=m;j++) b[i+l*j]=b[i];} DP (); ans=inf;for (int i=0;i<30;i+=2) ans=min (Ans,dp[l*m][i]); Cout<<ans<<endl;}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
! HDU 1494 running Kart-dp-