CodeForces - 258D:Little Elephant and Broken Sorting(概率DP)
题意:长度为n的排列,m次交换xi, yi,每个交换x,y有50%的概率不发生,问逆序数的期望 。n, m <= 1000
思路:我们只用维护大小关系,dp[i][j]表示位置i的数比位置j的数大的概率。
那么每次交换x和y。 假设x<y,那么区间就有三种: [1,x-1],[x+1,y-1], [y+1,N], 不难证明这三个区间和xy处的逆序对关系变为二者和的一半。
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
double dp[maxn][maxn],ans; int a[maxn];
int main()
{
int N,M,x,y; scanf("%d%d",&N,&M);
rep(i,,N) scanf("%d",&a[i]);
rep(i,,N)
rep(j,,N)
dp[i][j]=a[i]>a[j];
rep(i,,M){
scanf("%d%d",&x,&y);
rep(j,,N){
if(j==x||j==y) continue;
dp[j][x]=dp[j][y]=(dp[j][x]+dp[j][y])/;
dp[x][j]=dp[y][j]=(dp[x][j]+dp[y][j])/;
}
dp[x][y]=dp[y][x]=0.5;
}
rep(i,,N) rep(j,i+,N) ans+=dp[i][j];
printf("%.6lf\n",ans);
return ;
}
CodeForces - 258D:Little Elephant and Broken Sorting(概率DP)的更多相关文章
- 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 ...
- CF 258 D. Little Elephant and Broken Sorting
D. Little Elephant and Broken Sorting 链接 题意: 长度为n的序列,m次操作,每次交换两个位置,每次操作的概率为$\frac{1}{2}$,求m此操作后逆序对的期 ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- codeforces 768 D. Jon and Orbs(概率dp)
题目链接:http://codeforces.com/contest/768/problem/D 题意:一共有k种球,要得到k种不同的球至少一个,q个提问每次提问给出一个数pi,问概率大小大于等于pi ...
- 2018.12.12 codeforces 935D. Fafa and Ancient Alphabet(概率dp)
传送门 概率dp水题. 题意简述:给你数字表的大小和两个数列,数列中为0的数表示不确定,不为0的表示确定的,求第一个数列字典序比第二个数列大的概率. fif_ifi表示第i ni~ ni n位第一个 ...
- 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\) 个数比 ...
随机推荐
- Linux 安装rabbitmq 遇到的一些问题
Linux下防火墙开启相关端口及查看已开启端口 https://www.cnblogs.com/pizitai/p/6518987.htmlhttps://www.cnblogs.com/blog-y ...
- android ui界面设计参数讲解
百度文库: http://wenku.baidu.com/link?url=s66Hw6byBEzmjL77doYL1YQN4Y_39F7MovaHKs5mVGrzTDOQCAmiM-1N_6Cdm- ...
- js 光标选中 操作
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ubuntu16.04 安装power shell
ubuntu16.04 安装power shell # Download the Microsoft repository GPG keys wget -q https://packages.micr ...
- mac 下测试各种IE版本
背景 作为前端开发,在谈到兼容性时不得不谈到IE浏览器,那么,如果在mac上该怎么测试各种版本的IE呢 方法 1. 下载VirtualBox虚拟器 2. 下载安装了对应版本的windows系统,htt ...
- byte[]与各种数据类型互相转换示例
public class TestCase { /** * short到字节数组的转换. */ public static byte[] shortToByte(short number) { int ...
- 为什么CPU要从单核发展到多核?
前言 这里首先直接给出结论:CPU从单核发展到多核的原因是如果维持单核,则为了提高CPU性能只能不断提高时钟频率,从而会导致CPU功耗急速上升,导致机箱过热,来不及散热. 历史 2004年,Intel ...
- OpenStack Mitaka Neutron SR-IOV配置
### 一.在所有节点(控制节点.计算节点) 1.修改BIOS ``` BOIS里面开启SR-IOV功能 开启 VT-d (inter virtualization technology)和 SR-I ...
- Algorithm3: 获得一个int数中二进制位为1 的个数
获得一个int数中二进制位为1 的个数 int NumberOfOne(int n){ int count = 0; unsig ...
- iOS TableView常见问题
Q:表视图只需要部分单元格,怎样删除下方多余的空白单元格? A:viewDidLoad中添加 self.tableView.tableFooterView=[[UIView alloc] init]; ...