Dynamic planning.
A complete self-thought and then looked at the eye others gave the sample test the program of the problem ...
The point is that there are many platforms, the distance is the first one, then a price for a length, asking the minimum cost from one platform to another
Dynamic planning ...
Writing is n^2, there should be n .... Pay attention to the size relationship of the beginning end point!!!
#include <stdio.h> Remember to open long long
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace Std;
Long long int a[10001];
Long long int dp[10001]={0};
int main ()
{
Long long int l1,l2,l3,c1,c2,c3;
scanf ("%lld%lld%lld%lld%lld%lld", &L1,&L2,&L3,&C1,&C2,&C3);
int num;
scanf ("%d", &num);
int Qi,zhong;
scanf ("%d%d", &qi,&zhong);
if (qi>zhong) swap (Qi,zhong);
int i,j;
for (i=2;i<=num;i++) scanf ("%lld", &a[i]);
for (i=qi;i<=zhong;i++)
{
Long long int t=a[i]-a[i-1];
if (T<=L1) dp[i]=dp[i-1]+c1;
if (T>L1&&T<=L2) dp[i]=dp[i-1]+c2;
else dp[i]=dp[i-1]+c3;
}
dp[qi]=0;
for (i=qi;i<=zhong;i++)
{
for (j=1;j<=i-1;j++)
{
if (J<QI) break;
int JULI=A[I]-A[J];
if (JULI<=L3)
{
if (JULI<=L2)
{
if (JULI<=L1) {dp[i]=min (dp[j]+c1,dp[i]);}
else Dp[i]=min (DP[I],DP[J]+C2);
}
else Dp[i]=min (DP[I],DP[J]+C3);
}
}
}
for (i=1;i<=zhong;i++) printf ("%d", dp[i]);
printf ("%lld\n", Dp[zhong]);
return 0;
}
Write to another great God .... 15ms ...
#include <stdio.h>
Long w[10000]={0},f[100000]={0};
int main ()
{
Long I,S,T,N,L1,L2,L3,C1,C2,C3,S1,S2,S3;
int min (int,int);
scanf ("%ld%ld%ld%ld%ld%ld*", &L1,&L2,&L3,&C1,&C2,&C3);
scanf ("%ld*", &n);
scanf ("%ld%ld*", &s,&t);
if (s>t) s=s+t,t=s-t,s=s-t;
for (i=2;i<=n;i++)
scanf ("%d*", &w[i]);
S1=s,s2=s,s3=s;
for (i=s+1;i<=t;i++)
{
while (W[I]-W[S1]>L1) s1++;
while (W[I]-W[S2]>L2) s2++;
while (W[I]-W[S3]>L3) s3++;
if (s1<i)
F[i]=min (min (f[s1]+c1,f[s2]+c2), F[S3]+C3);
Else
if (s2<i) f[i]=min (F[S2]+C2,F[S3]+C3);
Else
F[I]=F[S3]+C3;
}
printf ("%ld", f[t]);
return 0;
}
int min (int s1,int s2)
{
if (S1<S2) return S1;
else return S2;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
URAL 1031 Railway Tickets