博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu多校第二场 1005 (hdu6595) Everything Is Generated In Equal Probability
阅读量:4538 次
发布时间:2019-06-08

本文共 1777 字,大约阅读时间需要 5 分钟。

题意:

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

题解:

先不考虑第一步随机从[1,N]里产生一个n,只考虑n给定的情况,求出了f[n],那么最后的结果就是

$  ans[N]=\frac{\sum_{n=1}^N f[n]}{N} $

赛时和队友利用找规律法和暴力模拟法推出

$ f[i]=\sum_{i=1}^{n-1}\frac{2i}{3} $

下面给出证明:

因为任意一个长度为n的全排列,其所含的逆序对的期望为

$ \binom{n}{2}/2 $ (不难理解,就是随便取两个点交换一下就出来一个逆序对)

而取出的那一个非连续子序列,我们把它里面的数字离散化以后也是一个全排列,所以

$ f[i]=\binom{n}{2}/2+\frac{1}{2^i}\sum_{j=0}^i\binom{i}{j}f[j] $

移项,得到递推公式

$ f[i]=\frac{2^{i-1}}{2^i-1}\binom{n}{2}/2+\frac{1}{2^i-1}\sum_{j=0}^{i-1}\binom{i}{j}f[j] $

f[1]=0,不难推出通项公式

$ f[i]=\sum_{i=1}^{n-1}\frac{2i}{3} $

代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
const int MOD = 998244353;#define rep(i,n,m) for(int i=n;i<=m;++i)const double eps = 1e-16;#define ll long longusing namespace std;const int maxn = 10000000;const int maxm = 2e5 + 10;const int inf = 1 << 28;typedef pair
P;#define zero(a) fabs(a)
'9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = 10 * x + ch - '0'; ch = getchar(); } return x * f;}ll quick_mod(ll x, ll n) { ll res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n = n >> 1; } return res;}ll a[3005];void init(){ a[0] = a[1] = 0; a[2] = 2; for (int i = 3; i <= 3000; ++i) a[i] = a[i - 1] + (i - 1) * 2; for (int i = 1; i <= 3000; ++i) a[i] += a[i - 1];}int main(){ ll n; init(); while (~scanf("%lld", &n)) { if (n == 1) { cout << "0" << endl; continue; } ll a1 = a[n]; ll b = 3 * n; ll x = quick_mod(b, MOD - 2); cout << a1 % MOD * x % MOD<

 

转载于:https://www.cnblogs.com/isakovsky/p/11247444.html

你可能感兴趣的文章
channel vs mutex
查看>>
页面布局(--FlowLayout,--BorderLayout,--GridLayout)
查看>>
实验吧--web--你真的会php吗
查看>>
vue组件化学习第二天
查看>>
网络枚举工具推荐
查看>>
003LeetCode--LongestSubstring
查看>>
quarzt(官方)---给自己看的文档(SchedulerListeners)-8
查看>>
Linux-慕课网学习笔记-3-1命令格式
查看>>
AJAX入门介绍
查看>>
[算法竞赛入门]第一章_算法概述
查看>>
SQL反模式笔记3——主键规范
查看>>
简单粗暴,微生物生态研究中常用数据库简介--转载
查看>>
Oracle -操作数据库
查看>>
c - 给分数分级别
查看>>
chrome 调试
查看>>
luoguP2774 方格取数问题
查看>>
tcp/ip协议各层的理解与
查看>>
python中的setdefault()方法
查看>>
转 VSFTP用户权限管控
查看>>
poj2420 A Star not a Tree? 模拟退火
查看>>