[Dp] [path] P1052 compression across the river

 (Bigwigs too strong) can skip steps 1-10 every time, because the lcm (1 .... 10) = 2520, then we can jump from 2520 forward, this distance can be seen as not, so the distance difference film 2520, the compression space.

Title Description

There is a single-plank bridge on the river, a frog want to jump from one side of the river along the difficult path. There are some stones on the bridge, frogs hate to step on the stones. The bridge length and a skip distance of frogs are positive integers, we can put in single frog point may arrive as a string of integer points on the number line: 0,1, ..., L 0 , . 1 , ... , L ( wherein L L is the length of the bridge). Coordinates 0 indicates the starting point 0 of the bridge, coordinates L indicates the end point L of the bridge. Frog from the starting point of the bridge, kept jumping to the finish direction. A jump distance S S to T any positive integer between T (including S, T S , T). When the frog jump or skip coordinates L when L point, even out of the frog has a difficult path.

Title given in single length L L, frog jump distance S, T S , T, stone bridge position. Your task is to determine the frog in order to cross the river, the minimum required number of stepping stones.

Input and output formats

Input formats:

 

First line . 1 a positive integer L (. 1 \ Le L \ Le ^ 10. 9) L ( . 1 L . 1 0 . 9 ), indicates the length of a wooden bridge.

The second line has . 3 3 a positive integer S, T, M S , T , the minimum distance M, each represent a jump of the frog, and from the maximum number of stone bridge, wherein 1 \ le S \ le T \ le 10 . 1 S T . 1 0, . 1 \ Le M \ 100 Le . 1 M . 1 0 0.

The third row has M M different positive integers which represent M M A stone in position on the number line (data start and end of the bridge to ensure that no stones). All separated by a space between adjacent integers.

 

Output formats:

 

An integer representing the number of Frogger stones requires a minimum walked on.

 

Sample input and output

Input Sample # 1:
10
2 3 5
2 3 5 6 7
Output Sample # 1: 
2

Explanation

For 30% of the data, L \ 10000 Le L . 1 0 0 0 0;

For all of the data, L \ ^. 9 Le 10 L . 1 0 . 9.

 

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+5;
const int mod=2520;
int l,s,t,m;
int pos[maxn],d[maxn];
int vis[maxn],dp[maxn];
int ant=maxn;
int main()
{
    scanf("%d",&l);
    scanf("%d %d %d",&s,&t,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&pos[i]);
    }
    sort(pos+1,pos+1+m);
    for(int i=1;i<=m;i++)
    {
        d[i]=(pos[i]-pos[i-1])%mod;
    }
    for(int i=1;i<=m;i++)
    {
        pos[i]=pos[i-1]+d[i];
        vis[pos[i]]=1;
    }
    l=pos[m];
    for(int i=1;i<=l+t;i++)
        dp[i]=m;
    for(int i=1;i<=l+t;i++)
    {
        for(int j=s;j<=t;j++)
        {
            if(i>=j)
                dp[i]=min(dp[i],dp[i-j]);

            //cout<<dp[i]<<" ";
        }
        dp[i]+=vis[i];
        //cout<<endl;
    }
    for(int j=l;j<=l+t;j++)
        ant=min(ant,dp[j]);
    printf("%d\n",ant);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Diliiiii/p/11129074.html