Little Elephant and Broken Sorting

怎么感觉这个状态好难想到啊。。

dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率。转移好像比较显然。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0); using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < ) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;} int n, m, a[N];
double dp[N][N]; int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
if(a[i] > a[j]) dp[i][j] = ;
while(m--) {
int a, b; scanf("%d%d", &a, &b);
for(int i = ; i <= n; i++) {
if(i == a || i == b) continue;
dp[i][a] = dp[i][b] = (dp[i][a] + dp[i][b]) / ;
dp[a][i] = dp[b][i] = (dp[a][i] + dp[b][i]) / ;
}
dp[a][b] = dp[b][a] = 0.5;
}
double ans = ;
for(int i = ; i <= n; i++)
for(int j = i + ; j <= n; j++)
ans += dp[i][j];
printf("%.12f\n", ans);
return ;
} /*
*/

Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp的更多相关文章

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

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

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

  3. CF 258 D. Little Elephant and Broken Sorting

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

  4. UESTC 2015dp专题 F 邱老师看电影 概率dp

    邱老师看电影 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

  5. Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP

    D. Bad Luck Island Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/pr ...

  6. CodeForces - 258D:Little Elephant and Broken Sorting(概率DP)

    题意:长度为n的排列,m次交换xi, yi,每个交换x,y有50%的概率不发生,问逆序数的期望  .n, m <= 1000 思路:我们只用维护大小关系,dp[i][j]表示位置i的数比位置j的 ...

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

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

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

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

  9. Codeforces 765F Souvenirs 线段树 + 主席树 (看题解)

    Souvenirs 我们将询问离线, 我们从左往右加元素, 如果当前的位置为 i ,用一棵线段树保存区间[x, i]的答案, 每次更新完, 遍历R位于 i 的询问更新答案. 我们先考虑最暴力的做法, ...

随机推荐

  1. (十一) UVC调节亮度

    目录 UVC调节亮度 引入 硬件协议速览 代码框架 属性初始化 属性支持查询 具体属性值获取 具体属性值设置 代码实现 title: UVC调节亮度 date: 2019/4/23 20:30:00 ...

  2. Linux记录-GC值

    jmap -heap pid 查看gc情况: jstat -gc PID 刷新频率 jstat -gc 12538 5000 导出堆内存dump 文件: jmap -dump:file=文件名.bin ...

  3. jQuery第1天

    概念 jQuery 是一个 JavaScript 库,其实就是通过 原生JS 封装了的很多的 方法 和 属性. JS 库特点 JavaScript 库:由第三方开发者基于原生 JS 基础上,封装了很多 ...

  4. HBase读写的几种方式(三)flink篇

    1. HBase连接的方式概况 主要分为: 纯Java API读写HBase的方式: Spark读写HBase的方式: Flink读写HBase的方式: HBase通过Phoenix读写的方式: 第一 ...

  5. Linux基础命令(三)——>文件过滤及内容编辑处理命令

    1.cat   合并文件或查看文件内容 基本功能:cat   test.txt     查看文件内容 也可以多文件显示 cat  test1.txt test2.txt >test3.txt   ...

  6. CSS之Background

    实验环境 [Windows 10] Chrome 73.0.3683.103(386,64bit) background作用范围 content+padding 参考文献 [1] CSS backgr ...

  7. eclipse出现jdk版本更新导致无法启动

    启动出现的问题,截图: 解决办法: 1.找到自己jdk安装的bin目录,我的安装目录是:F:\jdk\bin 2.修改eclipse安装目录下的eclipse.ini,添加 -vmF:\jdk\bin ...

  8. Nodejs一键实现微信内打开网页url自动跳转外部浏览器访问的功能

    前言 现如今微信对第三方推广链接的审核是越来越严格了,域名在微信中分享转发经常会被拦截,一旦被拦截用户就只能复制链接手动打开浏览器粘贴才能访问,要不然就是换个域名再推,周而复始.无论是哪一种情况都会面 ...

  9. word20170105订酒店 hotel reservation有用的词和句子

    有用的词: hotel reservation/booking: 酒店预订 standard room:标准间 suite: 套房 king size bed: 大床房 double bed:双床房 ...

  10. 如何安装zsh,终极shell

    1,教程 教程 上知乎直接搜索终极shell也可以,话不多说,直接自己看教程吧 2,总之就是 sudo apt-get install zsh chsh ...修改设置 wget下载oh-my-zsh ...