Codevs 1105 River Crossing 2005 Noip National League increase Group

Source: Internet
Author: User
Tags min time limit

1105 River crossing 2005 Noip National League increase group
time limit: 1 s
Space limit: 128000 KB
Title level: Diamond Diamond
Title Description descript Ion
There is a single-plank bridge on the river, and a frog wants to jump from one side of the river to the other along the plank. There were some stones on the bridge, and the frogs hated stepping on the stones. Since the length of the bridge and the distance that the frog skips all are positive integers, we can think of the point where the frog may arrive on the single plank as a series of the whole hour on the axis: 0,1,......,l (where L is the length of the bridge). A point with a coordinate of 0 represents the starting point of the bridge, and the point with the L coordinates represents the end point of the bridge. The frog jumps from the beginning of the bridge to the final direction. The distance of a single hop is any positive integer (including s,t) between S and T. When a frog jumps or jumps over a point with a coordinate of l, even if the frog has jumped out of the plank. The
topic gives the length of the bridge, the distance of the frog jumping s,t, and the location of the stone. Your task is to determine the minimum number of stones a frog will need to step across the river.
Input Description Input Description
The first line has a positive integer L (1<=l<=109), which indicates the length of the bridge. The second line has three positive integer s,t,m, which indicates the frog's minimum distance, maximum distance, and the number of stones on the bridge, of which 1<=s<=t<=10,1<=m<=100. The third line has m different positive integers representing the position of the M-Stone on the axis (the data ensures that there are no stones at the beginning and end of the bridge). All adjacent integers are separated by a space. The
Output description output Description
Outputs include only an integer that indicates the minimum number of stones a frog needs to step across the river.
Sample Input
2
3 5
2 3 5 6 7
Sample Output Example output
2
data range and tips for size & Hint
Data size
for 30% of data,l<=10000;
for all data, l<=109.
Category Tags Tags
dynamic planning Continental region Noip National League increase group 2005

/* violence 30. The equation is obviously f[i]=min (F[i]+a[i],f[j]). */#include <iostream> #include <cstdio> #
Define MAXN 10000001 using namespace std;
int n,f[maxn],s,t,m,x,ans=1e9;
BOOL A[MAXN];
    int main () {scanf ("%d", &n), scanf ("%d%d%d", &s,&t,&m);
    for (int i=1;i<=n+t;i++) f[i]=1e9;
    f[0]=0;
    for (int i=1;i<=m;i++) scanf ("%d", &x), a[x]=true;
        for (int i=0;i<=n;i++) for (int j=i+s;j<=i+t;j++) {if (A[j]) f[j]=min (F[i]+1,f[j]);
      else F[j]=min (F[j],f[i]);
    } for (int i=n;i<=n+t;i++) ans=min (Ans,f[i]);
    printf ("%d", ans);
return 0; }
/* dp+ discretization.
L<=10^9.
Then Ben Konjac Konjac want to roll around with a rolling array (grunt ~) and then bright have a state conflict (or maybe no mental low so don't want to come over Orz.) The positive solution is discretized.
Actually began to think of, but afraid to influence the answer is ...
Discretization is still more obvious.
If the distance between two stones is greater than T, set to T.
Because this distance is too long in the inside Tigger is useless in the last valid state or the block I stone position x is transferred to [X+s,x+t], the i+1 block stone position y is transferred from [y-s,y-t] to Y. */#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define MAXN
100001 using namespace std;
int N,F[MAXN],S,T,M,X,ANS=1E9,W[MAXN];
BOOL A[MAXN];
    int main () {memset (f,127/3,sizeof f);
    scanf ("%d", &n);
    scanf ("%d%d%d", &s,&t,&m);
    f[0]=0;
    for (int i=1;i<=m;i++) scanf ("%d", &w[i]);
    Sort (w+1,w+m+1);
        if (s==t) {ans=0;
        for (int i=1;i<=m;i++) if (w[i]%t==0) ans++;
        printf ("%d", ans);
    return 0;
    } n=0;
        for (int i=1;i<=m;i++) {int x=w[i]-w[i-1];
        int xx=min (X,T);
        N+=xx;
    A[n]=true; } for (int i=0;i<=n;i++) for (int j=i+s;j<=i+t;j++) {if (A[j]) f[j]=min (f[i]+1,F[J]);
      else F[j]=min (F[j],f[i]);
    } for (int i=n;i<=n+t;i++) ans=min (Ans,f[i]);
    printf ("%d", ans);
return 0; }

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.