题意:长度为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)的更多相关文章

  1. Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp

    Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #incl ...

  2. CodeForces 258D Little Elephant and Broken Sorting(期望)

    CF258D Little Elephant and Broken Sorting 题意 题意翻译 有一个\(1\sim n\)的排列,会进行\(m\)次操作,操作为交换\(a,b\).每次操作都有\ ...

  3. 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 ...

  4. CF 258 D. Little Elephant and Broken Sorting

    D. Little Elephant and Broken Sorting 链接 题意: 长度为n的序列,m次操作,每次交换两个位置,每次操作的概率为$\frac{1}{2}$,求m此操作后逆序对的期 ...

  5. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

  6. codeforces 768 D. Jon and Orbs(概率dp)

    题目链接:http://codeforces.com/contest/768/problem/D 题意:一共有k种球,要得到k种不同的球至少一个,q个提问每次提问给出一个数pi,问概率大小大于等于pi ...

  7. 2018.12.12 codeforces 935D. Fafa and Ancient Alphabet(概率dp)

    传送门 概率dp水题. 题意简述:给你数字表的大小和两个数列,数列中为0的数表示不确定,不为0的表示确定的,求第一个数列字典序比第二个数列大的概率. fif_ifi​表示第i ni~ ni n位第一个 ...

  8. CF258D Little Elephant and Broken Sorting/AGC030D Inversion Sum 期望、DP

    传送门--Codeforces 传送门--Atcoder 考虑逆序对的产生条件,是存在两个数\(i,j\)满足\(i < j,a_i > a_j\) 故设\(dp_{i,j}\)表示\(a ...

  9. CF258D Little Elephant and Broken Sorting (带技巧的DP)

    题面 \(solution:\) 这道题主要难在考场上能否想到这个思路(即如何设置状态)(像我这样的蒟蒻就想不到呀QAQ)不过这一题确实很神奇! \(f[i][j]:\)表示第 \(a_i\) 个数比 ...

随机推荐

  1. 【异常记录(五)】C# 无法发送具有此谓词类型的内容正文错误

    今天请求接口直接调了以前写好的方法,结果报了(405)不支持方法的错误,一看是GET写成POST了,改成GET之后,又报了无法发送具有此谓词类型的内容正文错误的错误 原来之前的方法里面有GetRequ ...

  2. hadoop安装时报错 /usr/local/hadoop-2.6.0-stable/hadoop-2.6.0-src/hadoop-hdfs-project/hadoop-hdfs/target/findbugsXml.xml does not exist

    安装时报错:Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (site) on project ...

  3. MyEclipse2014.Maven自动更新

    1.我把 "Do not automatically update dependencies from remote repositories" 和 "Download ...

  4. photoshop CS5制作具有立体感的按钮

    今天在学习用photoshop cs5制作html模板的过程中,遇到了立体感按钮的制作问题.当然按钮的立体感也可以用CSS来实现,这里主要是用PS来制作具有立体感的按钮. 我也是PS新手,下面的东西, ...

  5. ctci4.1

     ;      )         ;     )         return false;     else         return true; }

  6. 转载:10+ handy and reusable jQuery code snippets

    源地址:http://www.catswhocode.com/blog/10-handy-and-reusable-jquery-code-snippets Smooth scrolling to t ...

  7. Java SHA256/Base64转.NET(C#)实现---(华为云云市场.NET版本加密方式)

    前言: 工作需要,对接华为云应用市场的 API 接口,由于维护团队都是 .NET 所以用 .NET 来开发. 简单了解一下 SHA256 加密算法,本质就是一个 Hash,与 MD5 相比就是计算量大 ...

  8. js中字符串与数组的相互转换

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. HDU 3473 Minimum Sum 划分树,数据结构 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=3473 划分树模板题目,需要注意的是划分树的k是由1开始的 划分树: 参考:http://blog.csdn.ne ...

  10. LeetCode OJ:Jump Game II(跳跃游戏2)

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...