题解:P4669 [BalticOI 2011 Day2] Meetings
题意
有
思路
一开始看题蒟蒻是一点思路没有,打开题解看了一下感觉讲的不是很清晰就又自己想了一遍,最后理解了做法不想让其他人踩坑便写了此题解。
通过打表(这个只有自己手模几个小样例)我们发现答案不算太大可以直接从一开始模拟答案,设
我们发现,把
因为我们枚举的是答案,所以只要出现
这时候就有人问了,
秒啦!!!
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const ll N = 1e6 + 5;
ll n, p, v, a[N];
int main() {
read(n), read(p), read(v);
a[0] = 1;
for (int i = 1; a[i - 1] < n; ++i) {
for (int j = 2; j <= (i - v) / p; ++j)
a[i] = max(a[i], a[i - j * p - v] * j);
if (a[i] >= n) printf("%lld", i);
}
}