logo AlgoBeat OnlineJudge
登录 注册

「[XJTUPC 2026] 但是什么也不会改变 3」题解

作者: Dr_KC_Haus  ·  发布于 2026-07-08 20:37:41  ·  最后修改于 2026-07-08 20:50:49
已通过
审核员:joe_zxq 彩笔 · 2026-07-08 20:50:49

洛谷观看效果更佳


定义 是从 中选出 个不同数构成排列,且每个从第 位开始的数都在它前两个数的数值之间内的合法排列总数。

统计满足特定局部大小关系约束的排列子序列数量之和。分析条件,发现每个新加入的元素必须在前两个元素之间,且不能是三个数中的最大值或最小值。

对于任意长度 ),集合 中满足条件的排列数恒为 。这两种排列是从最小值开始交替插入最大值和次小值还有从最大值开始交替插入最小值和次大值。

所以,从 个数中选 个数的合法方案数为

最终答案为 。根据二项式恒等式 得:

最后取模得:

AC Code

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=998244353;
int n;
int c0=1;
int sum=(MOD+1)/2;
int mod_pow(int a,int e) {
    int res=1;
    a%=MOD;
    while(e>0) {
        if(e%2==1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        e/=2;
    }
    return res;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int pow2_n=mod_pow(2,n);
    int c1=n%MOD;
    int m=n%MOD;
    int cnt=(n-1)%MOD;
    int c2=(m*cnt)%MOD;
    c2=(c2*sum)%MOD;
    int s=(c0+c1+c2)%MOD;
    int v=(pow2_n-s+MOD)%MOD;
    cout<<(2*v)%MOD<<endl;
    exit(0);
}

暂无评论

登录 后即可评论。