Educational Codeforces Round 78 (Rated for Div. 2)F. Cards

F. Cards

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Consider the following experiment. You have a deck of mm cards, and exactly one card is a joker. nn times, you do the following: shuffle the deck, take the top card of the deck, look at it and return it into the deck.

Let xx be the number of times you have taken the joker out of the deck during this experiment. Assuming that every time you shuffle the deck, all m!m! possible permutations of cards are equiprobable, what is the expected value of xkxk? Print the answer modulo 998244353998244353.

Input

The only line contains three integers nn, mm and kk (1≤n,m<9982443531≤n,m<998244353, 1≤k≤50001≤k≤5000).

Output

Print one integer — the expected value of xkxk, taken modulo 998244353998244353 (the answer can always be represented as an irreducible fraction abab, where bmod998244353≠0bmod998244353≠0; you have to print a⋅b−1mod998244353a⋅b−1mod998244353).

Examples

input

Copy

1 1 1

output

Copy

1

input

Copy

1 1 5000

output

Copy

1

input

Copy

2 2 2

output

Copy

499122178

input

Copy

998244352 1337 5000

output

Copy

326459680

 

 

题意:求二项分布k次方的期望。

分析:

ans=\sum _i^n\binom{n}{i}p^i(1-p)^{n-i}i^k

ans=\sum _i^n\binom{n}{i}p^i(1-p)^{n-i}\sum _j^k\begin{Bmatrix} k\\j \end{Bmatrix}i^{\underline{j}}

ans=\sum _j^k\begin{Bmatrix} k\\j \end{Bmatrix}n^{\underline{j}} p^j \sum _i^{n-j}\binom{n-j}{i}p^i(1-p)^{n-i-j}

ans=\sum _j^k\begin{Bmatrix} k\\j \end{Bmatrix}n^{\underline{j}} p^j

然后O(k^2)处理出S(i,j),O(k)处理出n^\underline{i},累加一下答案就可以了。

#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long s[5004][5004];
long long p[5004];
long long qk(long long a,long long n){
    long long res = 1;
    while(n){
        if(n&1)res = res * a % mod;
        n>>=1;
        a=a*a%mod;
    }
    return res;
}
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    s[0][0]=1;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= i; ++j) {
            (s[i][j] = s[i-1][j-1] + 1LL*j*s[i-1][j]%mod % mod)%=mod;
        }
    }
    p[0]=1;
    for (int i = 1; i <= k; ++i) {
        p[i] = p[i-1]*(n-i+1)%mod;
    }
    long long res = 0;
    for (int i = 1; i <= k; ++i) {
        (res += s[k][i]*p[i]%mod*qk(qk(m,mod-2),i))%=mod;
    }
    cout<<res<<endl;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值