Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp
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的更多相关文章
- 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此操作后逆序对的期 ...
- UESTC 2015dp专题 F 邱老师看电影 概率dp
邱老师看电影 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...
- 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 ...
- CodeForces - 258D:Little Elephant and Broken Sorting(概率DP)
题意:长度为n的排列,m次交换xi, yi,每个交换x,y有50%的概率不发生,问逆序数的期望 .n, m <= 1000 思路:我们只用维护大小关系,dp[i][j]表示位置i的数比位置j的 ...
- 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 765F Souvenirs 线段树 + 主席树 (看题解)
Souvenirs 我们将询问离线, 我们从左往右加元素, 如果当前的位置为 i ,用一棵线段树保存区间[x, i]的答案, 每次更新完, 遍历R位于 i 的询问更新答案. 我们先考虑最暴力的做法, ...
随机推荐
- 限流redis+lua
限流==保险丝策略,可借助框架如spring cloud中Hystrix组件实现.今天介绍使用guava RateLimiter 类实现接口限流. 比如12306抢票: https://blog.cs ...
- Spring Security 登录校验 源码解析
传统情况下,在过滤器中做权限验证,Spring Secuirty也是在Filter中进行权限验证. 创建并注册过滤器 package com.awizdata.edubank.config; impo ...
- linux环境下安装lnmp出现php安装失败
找到lnmp1.5/include/version.sh文件打开修改 #Freetype_Ver='freetype-2.7' 为 #Freetype_Ver='freetype-2.9'即可
- 安装nova后解决登录没账号问题
找到laravel安装目录执行php artisan nova:user
- 社区发现算法 - Fast Unfolding(Louvian)算法初探
1. 社团划分 0x1:社区是什么 在社交网络中,用户相当于每一个点,用户之间通过互相的关注关系构成了整个网络的结构. 在这样的网络中,有的用户之间的连接较为紧密,有的用户之间的连接关系较为稀疏.其中 ...
- 【JS】前端文件下载(无刷新)方法总结
#传统方法 利用iframe 或 form.submit 或 windows.open直接向后端发请求,后端返回文件流,后端处理成功后会直接返回到页面,浏览器会整理并打开自己的保存下载文件机制 . 1 ...
- java 代码
java 里的 pandas tablesaw DataFrame 再有就是 spark 了 java 代码规范 Java8特性详解 lambda表达式 Stream Sonar 规则检测 sprin ...
- Hexo博客部署-使用github作为保存中转仓库
本篇是在VPS上搭建Hexo静态博客的第一篇博文,写本篇的目的一是纪念一下,二是作为一个部署文档保留. 博客地址 相关描述 VPS环境是在搬瓦工上安装的centos6(x86),1核,512MB,10 ...
- 1、IDEA的常用快捷键
一.常用的快捷键1.Ctrl+/ 或 Ctrl+Shift+/ 注释(// 或者/*...*/ )###2.Ctrl+D 复制行### 注意在MyEclipse中Ctrl+D的作用是删除行3.Ctrl ...
- python学习之 getattr vs __get__ vs __getattr __ vs __getattribute__ vs __getitem__
1. getattr.setattr.hasattr getattr比较常用,与setattr和hasattr一起出现,他们也是最容易理解的,下面是他的用法: class Profile(): nam ...