They have just finished the game and now are waiting for the result. But there's a tiny problem!. The judges have lost the paper of scores! Fortunately they have calculated sum of the scores before they get lost and also for some of the players they have remembered a lower bound on how much they scored. However, the information about the bounds is private, so Hasan only got to know his bound.
According to the available data, he knows that his score is at least $r$ and sum of the scores is $s$.
Thus the final state of the game can be represented in form of sequence of $p$ integers $a_1,a_2,...,a_p(0\le a_i)$- player's scores. Hasan is player number $1$, so $a_1\ge r$. Also $a_1+a_2+...+a_p=s$. Two clares are considered different if here exisits some position $i$ such that the value of $a_i$ differs in these states.
Once again, Hasan doesn't know the exact scores (he doesn't know his exact score as well). So he considers each of the final states to be equally probable to achieve.
Help Hasan find the probability of him winning.
It can be shown that it is in the form of $\frac{P}{Q}$ where $P$ and $Q$ are non-negative integers and $Q\ne 0,P\le Q$. Report the value of $P.Q^{-1}(\text{ mod }998244353)$.
Input
The only line contains three integers $p,s$ and $r(1\le p\le 100,0\le r\le s\le 5000)$- the number of players, the sum of scores of all players and Hasan's score, respectively.
Print a single integer - the probability of Hasan winning
Output
It can be shown that it is in the form of $\frac{P}{Q}$ where $P$ and $Q$ are non-negative integers and $Q\ne 0,P\le Q$. Report the value of $P.Q^{-1}(\text{ mod }998244353)$.
Examples
input
Copy
2 6 3
output
Copy
124780545
input
Copy
5 20 11
output
Copy
1
input
Copy
10 30 10
output
Copy
85932500
#include <bits/stdc++.h> using namespace std; #define ll long long int p, s, r, M=998244353; ll iv[5100], f1[5100], f2[5100], ans; int main() { ios::sync_with_stdio(0); cin.tie(0); iv[1]=f1[0]=f1[1]=f2[0]=f2[1]=1; for(int i=2; i<5100; ++i) { iv[i]=(M-M/i)*iv[M%i]%M; f1[i]=f1[i-1]*i%M; f2[i]=f2[i-1]*iv[i]%M; } cin >> p >> s >> r; for(int i=1; i<=p&&s-r*i>=0; ++i) ans+=(i&1?1:-1)*f1[s-r*i+p-1]*f2[s-r*i]%M*f2[i]%M*f2[p-i]%M; ans=(ans%M+M)*f1[p-1]%M*f1[s-r]%M*f2[s-r+p-1]%M; cout << ans; }
Không có nhận xét nào:
Đăng nhận xét