Topic Description Description
There is a log bridge over the river, and a frog wants to jump from one side of the river to the other side along the log bridge. There are some stones on the bridge, and frogs hate stepping on these stones. Since the length of the bridge is a positive integer from the distance the frog skips, we can think of the point where the frog might arrive on the log, as a string of dots on the axis: 0,1,......,l (where L is the length of the bridge). A point with a coordinate of 0 indicates the starting point of the bridge, and the point with the coordinate L indicates the end of the bridge. The frog starts at the beginning of the bridge and jumps towards the end. The distance of a jump is any positive integer (including s,t) between S and T. When the frog jumps or skips the point where the coordinates are L, even the frog has jumped out of the log.
The title gives the length of the log bridge, the distance range of the frog jumping s,t, and the position of the stone. Your task is to make sure that the frog wants to cross the river, at least the number of stones needed to step. Input description Input Description
Enter the first row has a positive integer L (1<=l<=109), indicating the length of the log bridge. The second line has three positive integer s,t,m, which represents the minimum distance of a frog, the maximum distance, and the number of stones on the bridge, of which 1<=s<=t<=10,1<=m<=100. The third line has m a different positive integer representing the position of the M stone on the number axis (data guarantee that the bridge's starting and ending points are not stone). All adjacent integers are separated by a single space. Output Description Description
The output includes only an integer that represents the minimum number of stones a frog needs to step across the river. Sample Input For example
2 3 5
2 3 5 6 7
Sample output Sample
2
Range of data and hints of the size & Hint
Data size
For 30% of the data,l<=10000;
For all the data, l<=10^9.
30 cents.
L A lot of things, you can't do it directly. Because there are few stones, there may not be any stone on a long road, so we can compress the path (the equivalent of discretization).
On how to compress, I tried every more than 1000 to press the path into 1000 of the way, but the effect is not very ideal. The distance between two stones a prime number is more ideal (may be data water bar ...). )。 There is also a rigorous proof: to find 10 within two number of the largest LCM (the table can be 90), can prove: when the path is greater than this number, any number can be combined. So you can make the distance between two stones 90 on it.
But the magic is, if for 30 points of data compression, always wa a point, I do not understand so only compressed more than 10000 of the data, God Benniu answer Qaq
Code:
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using
namespace Std;
const int size=200010;
int dp[size];
int num[size];
BOOL Shizi[size];
int main () {int l,s,t,m;
scanf ("%d%d%d%d", &l,&s,&t,&m);
for (int i=1;i<=m;i++) {scanf ("%d", &num[i]);
Sort (num+1,num+1+m);
for (int i=1;i<=m;i++) {if (l>10000) num[i]=min (num[i],num[i-1]+ (num[i]-num[i-1))%90);
Shizi[num[i]]=1;
} memset (Dp,63,sizeof (DP));
dp[0]=0; for (int i=1;i<=num[m]+t;i++) {for (int j=s;j<=t;j++) {if (i-j>=0) dp[
I]=min (Dp[i],dp[i-j]);
} Dp[i]+=shizi[i];
int ans=233333333;
for (int i=num[m];i<=num[m]+t;i++) ans=min (Ans,dp[i]);
printf ("%d", ans);
return 0; }/* g++ codevs1105.cpp-o codevs1105.exe-wall/*