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
 
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+;
typedef long long ll;
using namespace std; ll ksm(ll x,ll y)
{
ll ans=;
while(y)
{
if(y&)
{
ans=(ans*x)%;
}
y>>=;
x=(x*x)%;
} return ans;
}
int main()
{
ll n;
while(~scanf("%lld",&n))
{ ll ans=((n*n-)*ksm(,))%;
printf("%lld\n",ans); }
return ;
}

HDU-多校2-Everything Is Generated In Equal Probability(公式+逆元)的更多相关文章

  1. HDU 6595 Everything Is Generated In Equal Probability (期望dp,线性推导)

    Everything Is Generated In Equal Probability \[ Time Limit: 1000 ms\quad Memory Limit: 131072 kB \] ...

  2. hdu多校第二场 1005 (hdu6595) Everything Is Generated In Equal Probability

    题意: 给定一个N,随机从[1,N]里产生一个n,然后随机产生一个n个数的全排列,求出n的逆序数对的数量,加到cnt里,然后随机地取出这个全排列中的一个非连续子序列(注意这个子序列可以是原序列),再求 ...

  3. 【HDOJ6595】Everything Is Generated In Equal Probability(期望DP)

    题意:给定一个N,随机从[1,N]里产生一个n, 然后随机产生一个n个数的全排列,求出n的逆序数对的数量并累加ans, 然后随机地取出这个全排列中的一个子序列,重复这个过程,直到为空,求ans在模99 ...

  4. ACM的探索之Everything is Generated In Equal Probability! 后序补充丫!

    Problem Desciption: 百度翻译后的汉化: 参见博客:https://www.cnblogs.com/zxcoder/p/11253099.html https://blog.csdn ...

  5. ACM的探索之Everything Is Generated In Equal Probability(这真的是很有趣的话语丫!)

    ---------------------------------------步履不停,奋勇前进! ------------------------难度真的是蛮大丫!后序补充!

  6. [hdu6595]Everything Is Generated In Equal Probability

    计算一对逆序对的贡献,即在n个数期望要删多少步才能删掉其中的两个数,设f(n)表示此时的期望,则有方程$f[n]=3/4+(\sum_{i=2}^{n}f[i]\cdot c(n-2,i-2))/2^ ...

  7. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  8. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  9. 2015 HDU 多校联赛 5363 Key Set

    2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...

随机推荐

  1. python1.3集合知识点:

    #定义集合:{},集合是只有key没有value的字典,集合内元素不能重复!a={1,2,3,4,5,6}#列表转换成集合b=set([1,2,3,4,5])print(a,b) #集合对列表进行去重 ...

  2. Python初学者的自我修养,找到自己的方向

    今天是 Python专题 的第22篇文章,原本今天是准备和大家继续Python当中多线程的使用的相关内容.然而前两天有一个读者在后台问我,学习Python有哪些适合新手入门的小项目推荐,所以今天这篇临 ...

  3. 理解JavaScript的原型链

    1. 什么是对象 在JavaScript中,对象是属性的无序集合,每个属性存放一个原始值.对象或函数. 1.1 创建对象 在JavaScript中创建对象的两种方法: ① 字面上: var myObj ...

  4. FPN和他的子孙们

    FPN 方框里表示top down里每层有两个卷积操作  PAN:添加一个 bottom up线 NAS-FPN:基于搜索结构的FPN  Fully-conencted FPN:全连接的FPN  Si ...

  5. 最受欢迎的 15 大 Python 库(2017)

    核心库 1. NumPy (提交数: 15980, 贡献者数: 522) 当开始处理Python中的科学任务,Python的SciPy Stack肯定可以提供帮助,它是专门为Python中科学计算而设 ...

  6. java 打印流与commons-IO

    一 打印流 1.打印流的概述 打印流添加输出数据的功能,使它们能够方便地打印各种数据值表示形式. 打印流根据流的分类: 字节打印流 PrintStream 字符打印流 PrintWriter 方法: ...

  7. LeetCode198 House Robber(打家劫舍)

    题目 You are a professional robber planning to rob houses along a street. Each house has a certain amo ...

  8. python 文件读写with open模式r,r+,w,w+,a,a+的区别

    模式 可做操作 若文件不存在 是否覆盖 r 只能读 报错 - r+ 可读可写 报错 是 w 只能写 创建 是 w+ 可读可写 创建 是 a 只能写 创建 否,追加写 a+ 可读可写 创建 否,追加写

  9. 【ASP.NET Core学习】使用JWT认证授权

    概述 认证授权是很多系统的基本功能 , 在以前PC的时代 , 通常是基于cookies-session这样的方式实现认证授权 , 在那个时候通常系统的用户量都不会很大, 所以这种方式也一直很好运行, ...

  10. python对端口进行扫描

    使用cocket模块配合多线程对端口进行扫描,后续功能正在思考ing. import socket from multiprocessing.dummy import Pool as ThreadPo ...