P15625 [ICPC 2022 Jakarta R] Sharing Bread题解

· · 题解

题目传送门

首先要让每一个人都拿到面包的方案数可以看成是共有 N+1 个面包排成环形,最后第 N+1 个面包没有被取走的方案数,这样的话 a_i 每个值都可以在 1\sim N+1 的区间中任意选一个,故目前的序列总方案数就为 (N+1)^M。

然后我们考虑序列的合法概率,因为在 M 个人选择完毕后还会剩下 N+1-M 个面包机,而又因为环可以旋转,所以此时每个点都可能是第 N+1 个点,所以此时序列的合法概率就是 \frac{N+1-M}{N+1}。

最后我们根据根据总方案数和合法概率可以算出合法序列的期望值,就是 (N+1)^M\times \frac{N+1-M}{N+1}=(N-M+1)(N+1)^{M-1},直接输出就可以。

::::info[AC代码]

#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
long long ksm(long long a,int b){
    long long res=1;
    while(b){
        if(b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int n,m;
    cin>>n>>m;
    cout<<(n-m+1)*ksm(n+1,m-1)%mod;
    return 0;
}

::::