#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <unordered_set>
using namespace std;
int dfs(int L, int M, int S, int T, const vector<int>& cake_positions) {
vector<int> dp(L + 1, INT_MAX);
if (cake_positions[0] == 0) // 如果第一个位置是陷阱
dp[1] = 1;
else
dp[1] = 0;
unordered_set<int> cakes(cake_positions.begin(), cake_positions.end());
for (int i = 1; i <= L; ++i) {
if (cakes.count(i) == 0 || dp[i] == INT_MAX) {
continue;
}
for (int j = S; j <= T; ++j) {
int next_position = i + j;
if (next_position <= L) {
dp[next_position] = min(dp[next_position], dp[i] + 1);
}
}
}
return dp[L] == INT_MAX ? -1 : dp[L];
}
int main() {
int L, M, S, T;
cin >> L >> M;
cin >> S >> T;
vector<int> cake_positions(M);
for (int i = 0; i < M; ++i) {
cin >> cake_positions[i];
}
int result = dfs(L, M, S, T, cake_positions);
cout << result << endl;
return 0;
}
实在不懂chat出的答案怎么也改不对,输出一直是-1,寄了