题解 CF1536F Omkar and Akmar
link
最后停止的局面,连续的空格长度一定不超过
由于这是个环,所以可以确定最后的
每个人每时刻任何合法的选择都是最优策略。
考虑枚举最后空格的个数、空格的位置、放置顺序的圆排列数,答案为
注意其中系数
code
#include <vector>
#include <iostream>
#include <algorithm>
using i64 = long long;
const int P = 1e9 + 7;
int power(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = (i64) res * a % P;
a = (i64) a * a % P;
b >>= 1;
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> fac(n + 1), ifac(n + 1);
fac[0] = ifac[0] = 1;
for (int i = 1; i <= n; ++i)
fac[i] = (i64) fac[i - 1] * i % P;
ifac[n] = power(fac[n], P - 2);
for (int i = n; i > 1; --i)
ifac[i - 1] = (i64) ifac[i] * i % P;
auto choose = [&](int x, int y) -> int {
return (i64) fac[x] * ifac[y] % P * ifac[x - y] % P;
};
int ans = 0;
for (int i = n % 2; i <= n / 2; i += 2)
ans = (ans + (i64) choose(n - i, i) * 2 * fac[n - i - 1]) % P;
ans = (i64) ans * n % P;
std::cout << ans << '\n';
return 0;
}