Link: Https://www.vijos.org/p/1002
Analysis:
If p * x + (p + 1) * Y = Q (Q can be jumped to any position when the distance P and p + 1 are used ), Q ≥ p * (P-1) is a certain solution.
Because the range given in the question is 1 ≤ S ≤ T ≤ 10, when the distance between the adjacent two stones is not less than 8*9 = 72, then, we can think that the distance between them is 72. In this way, the range of the original question l is reduced to 100*72 = 7200, and the dynamic planning algorithm is completely sufficient.
However, when S = t, the above equations cannot be used. In this case, you only need to count the number of stones whose coordinates are multiples of s among all stones.
Note::
1. compression is required when DP is used.
2. Special answer s = T
Code:
# Include <istream> # include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; # define min (X, y) (x <Y? X: Y) # define INF 1e7int DP [100010]; int dd [100010]; int dis [105]; int main () {int L, S, T, M; int I, j; scanf ("% d", & L, & S, & T, & M); for (I = 1; I <= m; ++ I) scanf ("% d", & dis [I]); int ans = 0; If (S = T) {for (I = 1; I <m; ++ I) if (DIS [I] % s = 0) ++ ans ;} else {dis [0] = 0; sort (DIS, DIS + m + 1); memset (DD, 0, sizeof (dd); for (I = 1, j = 0; I <= m; ++ I) {If (DIS [I]-Dis [I-1])> 100) J + = 100; else J + = dis [I]-Dis [I-1]; dd [J] = 1;} int K = J + 100; dd [0] = 0; for (I = 1; I <= K; ++ I) {DP [I] = inf; For (j = s; j <= T; ++ J) {if (I <j) break; DP [I] = min (DP [I], DP [I-j] + dd [I]);} ans = DP [k];} printf ("% d \ n", ANS); Return 0 ;}