[Konjac konjac cultivation Plan] [VIJOS1002] [NOIP2005] cross the river

Source: Internet
Author: User

Description

given a line number, the starting point is 0, and some of the integer points on the axis have pebbles. Each interval that can be moved is [s,t]. The minimum number of stones to tread when reaching or exceeding L.

Input

the first line of input has a positive integer L (1 <= l <= 10^9).

The second line has three positive integers S,t,m,M represents the number of stones on the bridge, of which 1 <= S <= T <= 10,1 <= M <=.

The third line has M different positive integers represent the position of the M -stone on the axis ( the data guarantees no stones at 0 and L of the bridge ). All adjacent integers are separated by a space.

Output

The output includes only an integer that represents the minimum number of stones to tread.

Sample Input

10

2 3 5

2 3 5) 6 7

Sample Output

2

Solution

The DP equationis listed first , F[i] indicates the minimum number of stones to step on when I arrive , then F[i]=min (F[i-k]) (s<=k<=t).

and then found that the data range is 10^9, so need to shape pressure.

It can be found that if there is a stone in k+s*t and k+s*t+x (k>=0,x>0), if there is a scheme to cross the k+s*t, it canalso be crossed k+s* T+x.

specific proof when the S*t as T -S Add, easy to pass can reach k+s*t, can also reach k+s*t+x.

So it's just a matter of narrowing the distance over s*t to s*t .

1#include <cmath>2#include <ctime>3#include <queue>4#include <stack>5#include <cstdio>6#include <vector>7#include <cstring>8#include <cstdlib>9#include <iostream>Ten#include <algorithm> One #defineM 101 A #defineL 20001 - using namespacestd; - inta[m],f[l],l,m,s,t; the BOOLSto[l]; -Inlinevoidinit () { -scanf"%d%d%d%d",&l,&s,&t,&m); -      for(intI=1; i<=m;i++) +scanf"%d",&a[i]); -Sort (A +1, A +1+m); +     if(s==t) { A          for(intI=1; i<=m;i++) at             if(! (a[i]%s) &&a[i]<=l) -f[0]++; -printf"%d\n", f[0]); -         return; -     } -      for(intI=1, d;i<=m;i++){ in         if(a[i]-a[i-1]>s*t) { -d=a[i]-a[i-1]-s*T; to              for(intj=i;j<=m;j++) +a[j]-=D; -         } thesto[a[i]]=true; *     } $     if(l-a[m]>s*t) l=a[m]+s*T;Panax NotoginsengFill (f+1, f+1+l,m); -      for(inti=s;i<=l;i++){ thef[i]=f[i-s]; +          for(intJ=min (t,i); j>=s;j--) AF[i]=min (f[i],f[i-j]); thef[i]+=Sto[i]; +     } -printf"%d\n", F[l]); $ } $ intMain () { -Freopen ("river.in","R", stdin); -Freopen ("River.out","W", stdout); the init (); - fclose (stdin);Wuyi fclose (stdout); the     return 0; -}

[Konjac konjac cultivation Plan] [VIJOS1002] [NOIP2005] cross the river

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.