洛谷-1052
思路
Code
#include <bits/stdc++.h>
using namespace std;
#define _u_u_ ios::sync_with_stdio(false), cin.tie(nullptr)
#define cf int _o_o_;cin>>_o_o_;for (int Case = 1; Case <= _o_o_;Case++)
#define SZ(x) (int)(x.size())
inline void _A_A_();
signed main() {_A_A_();return 0;}
using ll = long long;
// #define int long long
int mod = 1e9 + 7;
const int maxn = 1e5 + 30;
const int N = 210, M = 5010;
const int inf = 0x3f3f3f3f;
int f[maxn], w[maxn], stone[maxn];
inline void _A_A_() {
#ifdef LOCAL
freopen("in.in", "r", stdin);
#endif
_u_u_;
int L;
cin >> L;
int s, t, m;
cin >> s >> t >> m;
for (int i = 1;i <= m;i++) {
cin >> stone[i];
}
sort(stone + 1, stone + 1 + m);
if (s == t) {
int res = 0;
for (int i = 1;i <= m;i++) {
if (stone[i] % s == 0) res++;
}
cout << res << "\n";
return;
}
else {
int last = 0;
int d = 0;
for (int i = 1;i <= m;i++) {
if (stone[i] - last >= 80) {
d += stone[i] - last - 80;
}
last = stone[i];
stone[i] -= d;
}
for (int i = 1;i <= m;i++) w[stone[i]] = 1;
L = stone[m] + 10;
for (int i = 1;i <= L;i++) {
f[i] = inf;
for (int j = s;j <= t;j++) {
if (i - j >= 0) f[i] = min(f[i], f[i - j] + w[i]);
}
}
cout << f[L] << "\n";
}
}
标签:1052,洛谷,int,stone,cin,80
From: https://www.cnblogs.com/FanWQ/p/16884823.html