A9846 | Inversions problem
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a permutation of $n$ numbers $p_{1},p_{2},...,p_{n}$ . We perform $k$ operations of the following type: choose uniformly at random two indices $l$ and $r$ ( $l<=r$ ) and reverse the order of the elements $p_{l},p_{l+1},...,p_{r}$ . Your task is to find the expected value of the number of inversions in the resulting permutation.
输入格式
The first line of input contains two integers $n$ and $k$ ( $1<=n<=100$ , $1<=k<=10^{9}$ ). The next line contains $n$ integers $p_{1},p_{2},...,p_{n}$ — the given permutation. All $p_{i}$ are different and in range from 1 to $n$ .
The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
- In subproblem G1 ( $3$ points), the constraints $1<=n<=6$ , $1<=k<=4$ will hold.
- In subproblem G2 ( $5$ points), the constraints $1<=n<=30$ , $1<=k<=200$ will hold.
- In subproblem G3 ( $16$ points), the constraints $1<=n<=100$ , $1<=k<=10^{9}$ will hold.
The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
- In subproblem G1 ( $3$ points), the constraints $1<=n<=6$ , $1<=k<=4$ will hold.
- In subproblem G2 ( $5$ points), the constraints $1<=n<=30$ , $1<=k<=200$ will hold.
- In subproblem G3 ( $16$ points), the constraints $1<=n<=100$ , $1<=k<=10^{9}$ will hold.
输出格式
Output the answer with absolute or relative error no more than $1e-9$ .
输入输出样例
输入 #1
3 1 1 2 3
输出 #1
0.833333333333333
输入 #2
3 4 1 3 2
输出 #2
1.458333333333334
Consider the first sample test. We will randomly pick an interval of the permutation $(1,2,3)$ (which has no inversions) and reverse the order of its elements. With probability , the interval will consist of a single element and the permutation will not be altered. With probability  we will inverse the first two elements' order and obtain the permutation $(2,1,3)$ which has one inversion. With the same probability we might pick the interval consisting of the last two elements which will lead to the permutation $(1,3,2)$ with one inversion. Finally, with probability  the randomly picked interval will contain all elements, leading to the permutation $(3,2,1)$ with 3 inversions. Hence, the expected number of inversions is equal to .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted