HDU-多校2-Everything Is Generated In Equal Probability(公式+逆元)
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.
2
3
332748118
554580197
#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(公式+逆元)的更多相关文章
- HDU 6595 Everything Is Generated In Equal Probability (期望dp,线性推导)
Everything Is Generated In Equal Probability \[ Time Limit: 1000 ms\quad Memory Limit: 131072 kB \] ...
- hdu多校第二场 1005 (hdu6595) Everything Is Generated In Equal Probability
题意: 给定一个N,随机从[1,N]里产生一个n,然后随机产生一个n个数的全排列,求出n的逆序数对的数量,加到cnt里,然后随机地取出这个全排列中的一个非连续子序列(注意这个子序列可以是原序列),再求 ...
- 【HDOJ6595】Everything Is Generated In Equal Probability(期望DP)
题意:给定一个N,随机从[1,N]里产生一个n, 然后随机产生一个n个数的全排列,求出n的逆序数对的数量并累加ans, 然后随机地取出这个全排列中的一个子序列,重复这个过程,直到为空,求ans在模99 ...
- ACM的探索之Everything is Generated In Equal Probability! 后序补充丫!
Problem Desciption: 百度翻译后的汉化: 参见博客:https://www.cnblogs.com/zxcoder/p/11253099.html https://blog.csdn ...
- ACM的探索之Everything Is Generated In Equal Probability(这真的是很有趣的话语丫!)
---------------------------------------步履不停,奋勇前进! ------------------------难度真的是蛮大丫!后序补充!
- [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^ ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
- 2015 HDU 多校联赛 5363 Key Set
2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...
随机推荐
- Tarjan 做题总结
这两天Tarjan复习完后把题做了做.洛谷题单<图的连通性>已经做得差不多了.大部分是Tarjan的题,所以写一篇小总结. T1 [模板] 缩点 不多bb.我已经写过关于Tarjan模板的 ...
- 自定制格式化方式format
自定制格式化方式format # x='{0}{0}{0}'.format('dog') # # print(x) # class Date: # def __init__(self,year,mon ...
- C、C++、boost、Qt在嵌入式系统开发中的使用
概述 嵌入式系统开发相对来说属于偏底层的开发,也就是与硬件结合比较紧密,只能使用C/C++语言.对于做平台开发的人来说,C语言真的是很"古老"的语言,属于操作系统语言!好多人会觉得 ...
- pyinstaller 转 exe 的一些坑,以及解决
2020年7月30日 打包了一个程序,各种报错,记录一下1.有时候,这个pyinstaller 打包程序吧,会出现闪退一下,一般原因是因为某个包没有加载进来,或者是包所在的路劲下面有中文,这样打包成功 ...
- 关于 JavaScript 字符串的一个小知识
说起字符串,我们再熟悉不过了.接触编程的第一个经典任务就是输出字符串:Hello, world.但是你知道 JavaScript 字符串在计算机里是怎么表示的吗? 最简单直观但不太准确的的理解就是,字 ...
- CentOS7(Linux)源码安装MySQL5.7.X
介绍 软件应用最重要的就是数据库了,可是还有小伙伴不会在Linux上安装MySQL数据库,今天就来讲讲如何在CentOS7环境使用源码进行安装MySQL5.7.X. MySQL官网下载链接:https ...
- 校内测试:T1秋末的落叶(命题人gxl)官方题解
秋末的落叶 题解 传送门:https://www.luogu.com.cn/problem/U121886 Part 1:疏通题意 首先,我们从题意和样例解释中很容易提取到以下信息: \(1.\)本题 ...
- centos7 重装ssh服务
重装之前先要卸载之前安装的无法 通过rpm命令查看openssh的安装情况 rpm -qa openssh* 通过yum remove命令卸载 yum remove openssh* 重装: yum ...
- go module 获取码云私有仓库代码
因为码云免费组织有5人限制,其他人想获得代码 只能通过别的方式 go mod 底层使用的git 获取代码, 所以首先解决如何通过git clone代码 思路为通过ssh密钥的方式获取 首先在码云仓库部 ...
- centos7 下安装生物信息软件的问题小总结
1.安装samtools与bwa时: 缺少zlib库 下载zlib库 cd zlib/ CFLAGS="-O3 -fPIC" ./configure make make insta ...