CF 258 D. Little Elephant and Broken Sorting
D. Little Elephant and Broken Sorting
题意:
长度为n的序列,m次操作,每次交换两个位置,每次操作的概率为$\frac{1}{2}$,求m此操作后逆序对的期望。
分析:
f[i][j]表示i>i的概率,每次交换的概率为$\frac{1}{2}$,设交换的位置是x,y,那么$f[i][x]=\frac{f[i][x]+f[i][y]}{2}$,分别是不交换和交换后的概率的和除以2。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
double f[N][N];
int a[N]; int main() {
int n = read(), m = read();
for (int i = ; i <= n; ++i) a[i] = read();
for (int i = ; i <= n; ++i)
for (int j = i + ; j <= n; ++j)
f[i][j] = a[i] > a[j], f[j][i] = a[j] > a[i];
while (m --) {
int x = read(), y = read();
if (x == y) continue;
for (int i = ; i <= n; ++i) {
if (i == x || i == y) continue;
f[i][x] = f[i][y] = (f[i][x] + f[i][y]) / 2.0;
f[x][i] = f[y][i] = (f[x][i] + f[y][i]) / 2.0;
}
f[x][y] = f[y][x] = 0.5;
}
double ans = ;
for (int i = ; i <= n; ++i)
for (int j = i + ; j <= n; ++j) ans += f[i][j];
printf("%.10lf",ans);
return ;
}
CF 258 D. Little Elephant and Broken Sorting的更多相关文章
- Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp
Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #incl ...
- CodeForces 258D Little Elephant and Broken Sorting(期望)
CF258D Little Elephant and Broken Sorting 题意 题意翻译 有一个\(1\sim n\)的排列,会进行\(m\)次操作,操作为交换\(a,b\).每次操作都有\ ...
- CodeForces - 258D Little Elephant and Broken Sorting
Discription The Little Elephant loves permutations of integers from 1 to n very much. But most of al ...
- CF258D Little Elephant and Broken Sorting/AGC030D Inversion Sum 期望、DP
传送门--Codeforces 传送门--Atcoder 考虑逆序对的产生条件,是存在两个数\(i,j\)满足\(i < j,a_i > a_j\) 故设\(dp_{i,j}\)表示\(a ...
- CF258D Little Elephant and Broken Sorting (带技巧的DP)
题面 \(solution:\) 这道题主要难在考场上能否想到这个思路(即如何设置状态)(像我这样的蒟蒻就想不到呀QAQ)不过这一题确实很神奇! \(f[i][j]:\)表示第 \(a_i\) 个数比 ...
- CodeForces - 258D:Little Elephant and Broken Sorting(概率DP)
题意:长度为n的排列,m次交换xi, yi,每个交换x,y有50%的概率不发生,问逆序数的期望 .n, m <= 1000 思路:我们只用维护大小关系,dp[i][j]表示位置i的数比位置j的 ...
- 【CF】220B Little Elephant and Array
区间动态统计的好题. /* */ #include <iostream> #include <string> #include <map> #include < ...
- Noip前的大抱佛脚----赛前任务
赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...
- codeforces 258D
D. Little Elephant and Broken Sorting time limit per test 2 seconds memory limit per test 256 megaby ...
随机推荐
- Jboss Jmx-Console和 Jboss web-console安全设置
1.介绍 如果你暴露你的JBoss服务器通过网络(如通过启动服务器使用选项B 0.0.0.0或者通过改变jboss.bind.address首次出现0.0.0.0在.../jboss/server/d ...
- Oracle GoldenGate DDL 详细说明 使用手册(较早资料)
一. 概述 DDL 相关的参数包括:DDL.DDLERROR.DDLOPTIONS.DDLSUBST.DDLTABLE.GGSCHEMA. PURGEDDLHISTORY.PURGEMARKERHIS ...
- lua调用c++函数返回值作用
2015/05/28 lua调用c++接口,返回给lua函数的是压入栈的内容,可以有多个返回值.但是c++接口本身也是有返回值的,这个返回值也非常的重要,会决定最后返回到lua函数的值的个数. (1) ...
- web应用配置文件详解(web.xml)
转载链接地址:http://blog.csdn.net/guihaijinfen/article/details/8363839 <?xml version="1.0" en ...
- java中判断对象中属性值是否为空的函数
public boolean checkObjFieldIsNull(Object obj) throws IllegalAccessException { boolean flag = false; ...
- docker 自制CentOS 6-lnp镜像
环境准备 1台centos 6.5镜像虚拟机 febootstrap.docker febootstrap 安装 yum install -y yum-priorities && r ...
- codeforces 17D Notepad
codeforces 17D Notepad 题意 题解 TBD 更新模板(phi.欧拉降幂) 代码 #include<bits/stdc++.h> using namespace std ...
- JXL API总结
API参考: http://www.andykhan.com/jexcelapi/index.html 官网: http://jexcelapi.sourceforge.net/ 1. 创建可写的工作 ...
- 终端复用工具 tmux 基本操作教程
简介 在 Linux 操作环境下,终端操作是发挥 Linux 强大命令功能的重要途径,但在本地主机操作中,针对不同任务开启不同的终端,在使用时进行频繁的终端切换在某些场合下是一种使人分心和疲惫的操作, ...
- 2049. [SDOI2008]Cave 洞穴勘测【LCT】
Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...