hdu-1494-Run Kart

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.