题解
2023-08-20 20:58:39
发布于:广东
11阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
int L, S, T, M;
cin >> L >> S >> T >> M;
vector<long long> pos(M + 1);
for (int i = 1; i <= M; ++i) {
cin >> pos[i];
}
sort(pos.begin() + 1, pos.end());
if (S == T) {
long long ANS = 0;
for (int i = 1; i <= M; i++) {
if (pos[i] % S == 0)
ANS++;
}
cout << ANS;
return 0;
}
for (int i = 1; i <= M; i++) {
long long delta = pos[i] - pos[i - 1];
if (delta > 90) {
pos[i] = pos[i - 1] + delta % 90;
}
}
L = pos[M] + (L - pos[M]) % 90;
vector<long long> a(L + 1, 0);
for (int i = 1; i <= M; i++) {
a[pos[i]] = 1;
}
vector<long long> f(L + 1, INF);
f[0] = 0;
for (int i = 1; i <= L; i++) {
for (int j = S; j <= T; j++) {
long long pos1 = i - j;
if (pos1 < 0) break;
f[i] = min(f[i], f[pos1] + a[i]);
}
}
cout << f[L] << endl;
return 0;
}
这里空空如也
有帮助,赞一个