Topic links
http://acm.hdu.edu.cn/showproblem.php?pid=1494
State equation cannot be pushed out, this problem, personally think more difficult, often look
The nitrogen is treated as 14 states, 14 is 2 cards and 80% Dp[i][j] is the shortest time to run to the end of paragraph I, if the remaining J, if (k==0) 0 is for rushing over.
DP[J][K]=DP[J-1][K+5]+B[J];
else if (k==10) left 10 There are two cases from 9 come over from 14 come on
Dp[j][k]=min (Dp[j-1][14]+a[j],dp[j-1][9]+a[j]); else if (k>10&&k<=14) then only normal run over
Dp[j][k]=dp[j-1][k-1]+a[j];else of two options
Dp[j][k]=min (Dp[j-1][k-1]+a[j],dp[j-1][k+5]+b[j]); Code
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace Std;
int a[110];
int b[110];
int dp[110][20];
int main (void)
{
int i,j,k,l,n;
while (scanf ("%d%d", &l,&n) ==2)
{
for (i=1;i<=l;i++)
scanf ("%d", a+i);
for (i=1;i<=l;i++)
scanf ("%d", b+i);
memset (dp[0],inf,sizeof (dp[0));
dp[0][0]=0;
for (i=1;i<=n;i++)
{
for (j=1;j<=l;j++)
{
for (k=0;k<15;k++)
{
if (k==0)
DP[J][K]=DP[J-1][K+5]+B[J];
else if (k==10)
Dp[j][k]=min (Dp[j-1][9]+a[j],dp[j-1][14]+a[j]);
else if (k>10&&k<=14)
DP[J][K]=DP[J-1][K-1]+A[J];
Else
Dp[j][k]=min (Dp[j-1][k-1]+a[j],dp[j-1][k+5]+b[j]);
}
}
for (j=0;j<15;j++)
DP[0][J]=DP[L][J];
}
int ans=inf;
for (i=0;i<15;i++)
Ans=min (Ans,dp[l][i]);
printf ("%d\n", ans);
}
return 0;
}
hdu-1494-Run Kart