VIJOS-P1292 tickets

JDOJ 1404: VIJOS-P1292 tickets

https://neooj.com/oldoj/problem.php?id=1404

Description

A railway line with a n (2 <= n <= 10000) railway stations, each station of the line from the starting station are known. Fare between any two stations in the table below: Distance between Station - X fare 0 <X <= L1 C1 L1 <X <= L2 C2 L2 <X <= L3 C3 wherein L1, L2, L3, C1, C2, C3 are known positive integers, and (1 <= L1 <L2 <L3 <= 10 ^ 9, 1 <= C1 <C2 <C3 <= 10 ^ 9). Obviously if the distance between two stations is larger than L3, then from one station to another at least two buy tickets. Note: When using each ticket can only start from the end of a station to another station. You now need for a given line, obtains a minimum fare station B from station A on the line. can you do it?

Input

A first input file acts integer 6, L1, L2, L3, C1, C2, C3 (1 <= L1 <L2 <L3 <= 10 ^ 9, 1 <= C1 <C2 <C3 <= 10 ^ 9) these integers separated by a space. N is the number of second line station (2 <= N <= 10000). the third conduct two different integers a, B, separated by spaces. The next line contains N-1 between the distance from the first station to other stations. These distances increase in the order is set to a different positive integers. The distance between two adjacent stations is not more than L3. Given two minimum travel between station takes no more than 10 ^ 9, and the distance between any two stations does not exceed 10 ^ 9.

Output

Only one number in the output file, represents the minimum value from A to B to be spent. 

Sample Input

3 6 8 20 30 40 7 2 6 3 7 8 13 15 23

Sample Output

70 
 
Dynamic Programming water problem.
Ideas:
Input, computational expense plus function of classification discussed, movable return output.
I will not talk about the cost function, look at the code should be nothing issue.
Mainly about moving classified section.
From a to b enumeration, the answer is dp [b], because the title says the situation does not exist to buy two tickets, so no need to consider multiple votes.
Set minimum cost from the start state to i.
State transition equation is:
dp[i]=min(dp[i],dp[j]+cost[j,i]);
This question bin.
Then you find yourself WA a few points.
So you open a long long
Then the AC you.
 
code:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int l1,l2,l3,c1,c2,c3,n;
int a,b;
long long len[10001];
long long dp[10001];
long long cost(long long x,long long y)
{
    if(len[y]-len[x]<=l3 && len[y]-len[x]>l2)
        return c3;
    if(len[y]-len[x]<=l2 && len[y]-len[x]>l1)
        return c2;
    if(len[y]-len[x]<=l1)
        return c1;
}
int main()
{
    scanf("%d%d%d%d%d%d%d%d%d",&l1,&l2,&l3,&c1,&c2,&c3,&n,&a,&b);
    memset(dp,0x3f,sizeof(dp));
    dp[a]=0;
    len[1]=0;
    for(int i=2;i<=n;i++)
        scanf("%lld",&len[i]);
    for(int i=a;i<=b;i++)
        for(int j=a;j<i;j++)
            if(len[i]-len[j]<=l3)
                dp[i]=min(dp[i],dp[j]+cost(j,i));
    printf("%lld",dp[b]);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/fusiwei/p/11237219.html