It was simple and difficult afterwards. It was simple and difficult afterwards.
This problem if this \ (l\) is a big water problem, but the data is a bit difficult.
Obviously we can discretization, the specific operation is the distance between the point of indentation and points. What I'm using here is a 2520-indent.
\[2520=LCM (,..., 10) and 1 \leq s \leq T \leq 10\]
So we have a direct% of the distance between the two adjacent points 2520.
But pay attention to the handling of the \ (s=t\) situation. I refer to one of the methods in the solution.
The last stone after the end of the indentation is obviously not the end point, we have to get it out of the real end.
We look for the minimum value of the answer in the t\ length interval headed by the last stone, and we can transfer the state from any of these elements as the end point, and we take the smallest answer, which is optimal.
Code:
#include <cstdio> #include <cstring> #include <algorithm>const int maxn = 500005;int L, s, T, M;int dp[ Maxn];int stone[105], newstone[105], Newl;bool havestone[maxn];void solve () {int now = 0, ans = 0; for (int i = 1; I <= m; i++) {if ([Stone[i]-now)% s = = 0) {now = Stone[i]; ans++; } else if (now + (Stone[i] – now)% s <= l) today = Now + (Stone[i] – now)% s; } printf ("%d\n", ans);} int main () {scanf ("%d%d%d%d", &l, &s, &t, &m); for (int i = 1; I <= m; i++) scanf ("%d", &stone[i]); Std::sort (stone + 1, stone + M + 1); Memset (DP, 0x3f, sizeof DP); for (int i = 1; I <= m; i++) {newstone[i] = Newstone[i-1] + ((Stone[i]-stone[i-1])% 2520); Havestone[newstone[i]] = true; } Dp[0] = 0; for (int i = 1; I <= newstone[m] + t, i++) {for (int j = t; J >= S; j--) {if (I-j >= 0) {DP[i] = Std::min (Dp[i], dp[i-j] + (int) (havestone[i])); }}} int ans = 0x3f3f3f3f; for (int i = newstone[m]; I <= newstone[m] + t; i++) ans = std::min (ans, dp[i]); printf ("%d\n", ans); return 0;}
P1052 across the river