"Basic Exercise" "Linear dp+ discretization" codevs1105 The crossing of the river

Source: Internet
Author: User

Title Description Description

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 jumps once is a positive integer, we can think of the point that the frog may reachon the single-Plank island as a series of the whole hour on the axis:0 ,1 ,... ,L (where L is the length of the bridge). Coordinates of 0 Point representing the starting point of the bridge, the coordinates are L Point represents the end of the bridge. The frog jumps from the beginning of the bridge to the final direction. The distance of one jump is S to T Any positive integer between, including the s,t ). When the frog jumps or skips the coordinates for L point, even if the frog has jumped out of the plank.
The title gives the length of the plank bridge L , frog jumping distance range s,t , the position of the stone on the bridge. Your task is to determine the minimum number of stones a frog will need to step across the river.

Enter a description input Description

inputThe first line has a positive integer L (1<=L<=9 ), which indicates the length of the plank bridge. The second line has three positive integers S ,T ,M 1 <= s <= t <= 10 ,1<=M<= . The third line has M A different positive integer representing the M The position of a stone on the axis (the data guarantees that there are no stones at the beginning and end of the bridge). All adjacent integers are separated by a space.

outputs description output Description

Output include only an integer that indicates the minimum number of stones a frog needs to step across the river.

sample input to sample

Ten
235
23567

Sample output Sample outputs

2

data size & Hint

Data size


for 30% The data,L<=10000 ;

for all data,L<=9 .

The equation is obvious:

F[i] = min {f[i-x]} + stone[i];  X∈[s, T]ans = min {f[j]};  J∈[l, L+t-1]

Since the data is so large, it is clear that it should be discretized

The first discrete t, but how can not do not know whether Yang Zhizan teacher's courseware wrong. Codevs also said T, do not know why;

Refer to the explanation of least common multiple practices on Codevs:

only ask out the 1--10 inside any two number of least common multiple, and then take the largest, can prove that when the distance between the two stones is greater than the time, then each point greater than its parts can be a certain combination of these two numbers jump to, so when the distance between two stones is greater than this least common multiple, Then narrow their distances to this least common multiple.

after the path is compressed, the minimum number of stones can be calculated by DP. Set F[i] means the minimum number of stones to reach the first position.
then F[i]=min (F[i-j]+d[i]) (1<=i<=l+t) (s<=j<=t), D[i] Indicates whether there are stones in the first position.
The final answer is to find the smallest between L to L+t.

Though I don't know what's going on, it's the truth =

On the code, I have to hurry to the writing industry


--the spring is Peach blossom water, do not distinguish the source where to find.


Copyright NOTICE: Reprint Please specify source [ametake Copyright]http://blog.csdn.net/ametake Welcome to see

"Basic Exercise" "Linear dp+ discretization" codevs1105 The crossing of 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.