HDU-多校2-Everything Is Generated In Equal Probability(公式+逆元)
作者:互联网
Problem Description
One day, Y_UME got an integer N and an interesting program which is shown below:
Y_UME wants to play with this program. Firstly, he randomly generates an integer n∈[1,N] in equal probability. And then he randomly generates a permutation of length n in equal probability. Afterwards, he runs the interesting program(function calculate()) with this permutation as a parameter and then gets a returning value. Please output the expectation of this value modulo 998244353.
A permutation of length n is an array of length n consisting of integers only ∈[1,n] which are pairwise different.
An inversion pair in a permutation p is a pair of indices (i,j) such that i>j and pi<pj. For example, a permutation [4,1,3,2] contains 4 inversions: (2,1),(3,1),(4,1),(4,3).
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. Note that empty subsequence is also a subsequence of original sequence.
Refer to https://en.wikipedia.org/wiki/Subsequence for better understanding.
Each case starts with a line containing one integer N(1≤N≤3000).
It is guaranteed that the sum of Ns in all test cases is no larger than 5×104.
Y_UME wants to play with this program. Firstly, he randomly generates an integer n∈[1,N] in equal probability. And then he randomly generates a permutation of length n in equal probability. Afterwards, he runs the interesting program(function calculate()) with this permutation as a parameter and then gets a returning value. Please output the expectation of this value modulo 998244353.
A permutation of length n is an array of length n consisting of integers only ∈[1,n] which are pairwise different.
An inversion pair in a permutation p is a pair of indices (i,j) such that i>j and pi<pj. For example, a permutation [4,1,3,2] contains 4 inversions: (2,1),(3,1),(4,1),(4,3).
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. Note that empty subsequence is also a subsequence of original sequence.
Refer to https://en.wikipedia.org/wiki/Subsequence for better understanding.
Input There are multiple test cases.
Each case starts with a line containing one integer N(1≤N≤3000).
It is guaranteed that the sum of Ns in all test cases is no larger than 5×104.
Output For each test case, output one line containing an integer denoting the answer.
Sample Input 1 2 3
Sample Output 0 332748118 554580197
Source 2019 Multi-University Training Contest 2
Recommend liuyiding | We have carefully selected several similar problems for you: 6602 6601 6600 6599 6598 推导公式为(n*n-1 / 9)%998244353 套上公式求下逆元就好了 代码:
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<queue> #include<stack> #include<set> #include<vector> #include<map> #include<cmath> const int maxn=1e5+5; typedef long long ll; using namespace std; ll ksm(ll x,ll y) { ll ans=1; while(y) { if(y&1) { ans=(ans*x)%998244353; } y>>=1; x=(x*x)%998244353; } return ans; } int main() { ll n; while(~scanf("%lld",&n)) { ll ans=((n*n-1)*ksm(9,998244351))%998244353; printf("%lld\n",ans); } return 0; }
标签:HDU,Probability,ll,permutation,Equal,ans,integer,include,998244353 来源: https://www.cnblogs.com/Staceyacm/p/11240725.html