http://acm.hdu.edu.cn/showproblem.php?pid=
状态 dp[i][j] 表示第i段能量为j的时间
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
const int maxn = 105;
const int inf = 1<<30;
int n,m;
int a[maxn],b[maxn];
int dp[maxn*maxn][20];
int mins( int a,int b,int c )
{
a = a<=b?a:b;
return a<=c?a:c;
}
int getDP()
{
memset(dp,-1,sizeof(dp));
int cnt = n*m;
dp[0][0] = 0;
int q,w,e; //不用加速器
for( int i = 1; i <= cnt; i ++ )
{
for( int j = 0; j <= 14; j ++ )
{
q = w = e = inf;
if( j >= 1 && dp[i-1][j-1] != -1 ) //不用加速器
q = dp[i-1][j-1] + a[i%n];
if( j == 10 && dp[i-1][14] != -1 ) //能量为14时不用加速器
w = dp[i-1][14] + a[i%n];
if( j < 10 && dp[i-1][j+5] != -1 ) //用加速器
e = dp[i-1][j+5] + b[i%n];
int Min = mins( q,w,e );
if( Min != inf )
dp[i][j] = Min;
}
}
int ans = inf;
for( int i = 0; i <= 14; i ++ )
{
if( dp[cnt][i] != -1 && dp[cnt][i] < ans )
ans = dp[cnt][i];
}
return ans;
}
int main()
{
//freopen( "data.in","r",stdin );
while( scanf("%d%d",&n,&m) != EOF )
{
for( int i = 1; i <= n; i ++ )
{
scanf("%d",&a[i%n]);
}
for( int i = 1; i <= n; i ++ )
{
scanf("%d",&b[i%n]);
}
int ans = getDP();
printf("%d\n",ans);
}
return 0;
}