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\) 个数比 ...
随机推荐
- Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
一.linux中配置redis,使用java连接测试时报错: Exception in thread "main" redis.clients.jedis.exceptions.J ...
- Object.defineProperties——MEAN开发后台的Model层
Object.defineProperties是什么?有什么用? 这个问题比较听起来可能比较难以理解,确实我也是在项目中遇到的才会去想.以前看到<高级程序设计>的时候,有这么一种东西,定义 ...
- Educational Codeforces Round 54 (Rated for Div. 2) DE
D 给出一个无向图,需要删去一些边,想知道最后能有多少个点到1的距离还是过去那么短 如果求一个最短路,然后从删边的角度看,看起来很难做,但是如果从零开始加边就会有做法,如同prim那样,先加入和1直接 ...
- .net 下的 HttpRuntime.Cache 应用
using System;using System.Collections.Generic;using System.Diagnostics;using System.Linq;using Syste ...
- DLL_Delphi动态调用
1.动态调用DLL unit formMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Co ...
- php http post发送失败的问题
//params 是json对象private function HttpPost($url, $params){$data = http_build_query($params); //写 ...
- STOMP协议规范【转】
STOMP协议规范英文原文:http://stomp.github.io/stomp-specification-1.2.html STOMP协议规范译文原文:http://simlegate.com ...
- SPOJ-CLEANRBT-状压dp
CLEANRBT - Cleaning Robot #dynamic-programming #bfs Here, we want to solve path planning for a mobil ...
- taskset -pc PID 查看线程占用cpu核
taskset -pc PID 可以用于 查看 当前线程 对应绑定的 在 哪个核上面. 这个 可以用于 程序优化, 查看 哪个线程占用的 cpu 比重比较高 首先 可以通过 top -H - ...
- rsync的配置文件模板及简单介绍,命令及参数
必须知道推送有一个限速参数.--bwlimit=100 工作总必须要加.有三种模式,1.本地的模拟cp命令,在一个服务器2.远程的两个服务器之间,模拟scp3.以socket进程监听的方式启动rsyn ...