专栏文章
Dynamic Mex Problem 题解
个人记录参与者 1已保存评论 1
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @miqbnunu
- 此快照首次捕获于
- 2025/12/04 02:10 3 个月前
- 此快照最后确认于
- 2025/12/04 02:10 3 个月前
闲话
方法思路
我们可以轻松得出以下结论:
-
当 是偶数时:所有排列的 值都是 。这是因为每个排列中以序列最小值0作为最小值的子区间数总是偶数(因为一共有 个区间以序列最小值0为最小值,而 和 之中一定有一个偶数),因此 不会出现在集合 中, 值为 ,此时 的方案数为 ,其他为 。
-
当 是奇数时: 可能出现在集合 中,也可能不出现。如果 出现,则 值一定为 (就相当于把 分为了两个长度为偶数的序列,其中有一个包含 ,而根据上文,此时, 一定不在 中)。如果 不出现,则 值为 。具体来说:
- 当 前面有偶数个数时,集合 的 值为 。
- 当 前面有奇数个数时,集合 的 值为 。
此时 的方案数为。 的方案数为。其他为 。
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int mod = 1e9 + 7;
int n;
signed main(){
IOS;
cin >> n;
int ans = 1, las;
for(int i = 1; i <= n; i++) las = ans, ans *= i, ans %= mod;
if(n % 2 == 0){
cout << ans << '\n';
for(int i = 1; i <= n; i++) cout << 0 << '\n';
}
else{
cout << (n - 1) / 2 * las % mod << '\n';
cout << (n + 1) / 2 * las % mod << '\n';
for(int i = 2; i <= n; i++) cout << 0 << '\n';
}
return 0;
}
相关推荐
评论
共 1 条评论,欢迎与作者交流。
正在加载评论...