1 条题解

  • 0
    @ 2025-8-24 23:09:53

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar LFL
    **

    搬运于2025-08-24 23:09:53,当前版本为作者最后更新于2025-02-14 19:09:39,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


    出题人题解。

    方法思路

    我们可以轻松得出以下结论:

    1. nn 是偶数时:所有排列的 mexmex 值都是 00。这是因为每个排列中以序列最小值0作为最小值的子区间数总是偶数(因为一共有 i×(ni+1)i \times (n - i + 1) 个区间以序列最小值 00 为最小值,而 iini+1n - i + 1 之中一定有一个偶数),因此 00 不会出现在集合 S(a)S(a) 中,mexmex 值为 00,此时 mex=0mex=0 的方案数为 n!n!,其他为 00

    2. nn 是奇数时00 可能出现在集合 S(a)S(a) 中,也可能不出现。如果 00 出现,则 mexmex 值一定为 11 (就相当于把 aa 分为了两个长度为偶数的序列,其中有一个包含 11,而根据上文,此时,11 一定不在 S(a)S(a) 中)。如果 00 不出现,则 mexmex 值为 00。具体来说:

      • 00 前面有偶数个数时,集合 S(a)S(a)mexmex 值为 11
      • 00 前面有奇数个数时,集合 S(a)S(a)mexmex 值为 00

      此时 mex=0mex=0 的方案数为(n1)2×(n1)!\dfrac{(n-1)}{2}\times(n-1)!mex=1mex=1 的方案数为n+12×(n1)!\dfrac{n+1}{2}\times(n-1)!。其他为 00

    #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

    信息

    ID
    11431
    时间
    2000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    0
    已通过
    0
    上传者