标签:HDU Probability ll permutation Equal ans integer include 998244353
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.
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
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。