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 = ...
随机推荐
- beyond compare4 密钥 亲测可用
beyond compare4过了试用期: 密钥: w4G-in5u3SH75RoB3VZIX8htiZgw4ELilwvPcHAIQWfwfXv5n0IHDp5hv1BM3+H1XygMtiE0-J ...
- 理解JavaScript的原型链
1. 什么是对象 在JavaScript中,对象是属性的无序集合,每个属性存放一个原始值.对象或函数. 1.1 创建对象 在JavaScript中创建对象的两种方法: ① 字面上: var myObj ...
- Tomcat Windows 内存设置
双击 bin 目录下 tomcat8w.exe,在 java 标签内修改内存配置
- Vulhub Docker环境部署
1:安装Linux 2:安装Docker : curl -s https://get.docker.com/ | sh 3:安装Docker-compose curl -s https://boots ...
- 2020-05-16:如何保证redis和mysql数据一致?
福哥答案2020-05-16:
- 5招详解linux之openEuler /centos7防火墙基本使用指南
防火墙是一种防火墙管理解决方案,可用于许多 Linux 发行版,它充当 Linux 内核提供的 iptables 数据包筛选系统的前端.在本指南中,将介绍如何为服务器设置防火墙,并向你展示使用管理工具 ...
- (Filter + Listener )Day18
Filter过滤器 filter是对客户端访问资源的过滤,符合条件的放行,不符合的不放行,并且可以对目标资源访问前后进行逻辑处理. 设置步骤 创建类实现Filter接口 在 doFilter 方法中编 ...
- Kubernetes基于haproxy实现ingress服务暴露
HAproxy Ingress控制器 HAproxy Ingress简介 HAProxy Ingress watches in the k8s cluster and how it builds HA ...
- vue_如何判断变量是数组还是对象
一.typeof判断数据类型(判断数组跟对象都返回object) console.log(typeof null); // "object" console.log(typeof ...
- 【译】GitHub 为什么挂?官方的可行性报告为你解答
本文翻译自 GitHub 官方博客<Introducing the GitHub Availability Report> 原文链接:https://github.blog/2020-07 ...