传送门——Codeforces

传送门——Atcoder


考虑逆序对的产生条件,是存在两个数\(i,j\)满足\(i < j,a_i > a_j\)

故设\(dp_{i,j}\)表示\(a_i>a_j\)的概率,每一次一个交换操作时\(O(n)\)地更新即可。

AGC030D就在模意义下运算,最后就乘上\(2^Q\)就行了

看着好简单啊就是想不到

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<vector>
#include<cmath>
#define ld long double
//This code is written by Itst
using namespace std; inline int read(){
int a = 0;
char c = getchar();
bool f = 0;
while(!isdigit(c) && c != EOF){
if(c == '-')
f = 1;
c = getchar();
}
if(c == EOF)
exit(0);
while(isdigit(c)){
a = a * 10 + c - 48;
c = getchar();
}
return f ? -a : a;
} ld dp[1010][1010];
int num[1010] , N , M; int main(){
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
//freopen("out","w",stdout);
#endif
N = read();
M = read();
for(int i = 1 ; i <= N ; ++i)
num[i] = read();
for(int i = 1 ; i <= N ; ++i)
for(int j = i - 1 ; j ; --j){
dp[i][j] = num[i] > num[j];
dp[j][i] = num[j] > num[i];
}
for(int i = 1 ; i <= M ; ++i){
int a = read() , b = read();
for(int j = 1 ; j <= N ; ++j)
if(j != a && j != b){
dp[j][a] = dp[j][b] = (dp[j][a] + dp[j][b]) * 0.5;
dp[a][j] = dp[b][j] = (dp[a][j] + dp[b][j]) * 0.5;
}
dp[a][b] = dp[b][a] = (dp[a][b] + dp[b][a]) * 0.5;
}
ld sum = 0;
for(int i = 1 ; i <= N ; ++i)
for(int j = i - 1 ; j ; --j)
sum += dp[j][i];
cout << fixed << setprecision(8) << sum;
return 0;
}

CF258D Little Elephant and Broken Sorting/AGC030D Inversion Sum 期望、DP的更多相关文章

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

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

  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 (看题解) 概率dp

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

  4. CF 258 D. Little Elephant and Broken Sorting

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

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

  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. 「AGC030D」Inversion Sum

    「AGC030D」Inversion Sum 传送门 妙啊. 由于逆序对的个数最多只有 \(O(n^2)\) 对,而对于每一个询问与其相关的逆序对数也最多只有 \(O(n)\) 对,我们可以对于每一对 ...

  8. 【AGC030D】Inversion Sum DP

    题目大意 有一个序列 \(a_1,a_2,\ldots,a_n\),有 \(q\) 次操作,每次操作给你两个数 \(x,y\),你可以交换 \(a_x,a_y\),或者什么都不做. 问你所有 \(2^ ...

  9. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

随机推荐

  1. 自定义控件详解(五):onMeasure()、onLayout()

    前言: 自定义控件的三大方法: 测量: onMeasure(): 测量自己的大小,为正式布局提供建议 布局: onLayout(): 使用layout()函数对所有子控件布局 绘制: onDraw() ...

  2. (网页)20个JS 小技巧超级实用

    转自CSDN: 1. 将彻底屏蔽鼠标右键 oncontextmenu=”window.event.returnValue=false”< table border oncontextmenu=r ...

  3. Django之form总结

    复习Django项目结构: 主要的文件:manage.py,url.py,views.py,settings.py,models.py manage.py:项目管理文件,一般不做修改. url.py: ...

  4. python基础知识回顾之字符串

    字符串是python中使用频率很高的一种数据类型,内置方法也是超级多,对于常用的方法,还是要注意掌握的. #author: Administrator #date: 2018/10/20 # pyth ...

  5. ALSA声卡驱动的DAPM(一)-DPAM详解

    最近使用tinymix 调试相应的音频通道,但是一直不知道音频通道的原理是什么.所以百度了一下,百度结果是与DPAM有关. 一.DAPM简介: DAPM是Dynamic Audio Power Man ...

  6. debian 7.4 安装配置

    改用debian差不多有半年了,之前一直用fedora,大概3年多,虽然软件包都很新,总是不太稳定,有点软件用着用着就自动退出了. 换了debain之后,这半年还真是一直没啥问题,这里总结了一些安装配 ...

  7. NavigationController相关颜色设置

    一.当push进去一个界面后,返回按钮颜色改变: self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

  8. 17秋 软件工程 团队第五次作业 Alpha Scrum3

    17秋 软件工程 团队第五次作业 Alpha Scrum3 今日完成的任务 杰麟:java后端学习: 世强:Android的部门基础信息模块的信息显示和对接后台: 港晨:后台管理登陆界面ui设计: 树 ...

  9. 免费代理IP地址列表

    代理地址最后验证日期:2017-8-28 纯真 66免费代理网 #推荐 西刺免费代理IP 酷伯伯HTTP代理 快代理 proxy360.cn 站大爷 Free Proxy List 年少#不稳定 全网 ...

  10. MapReduce全局变量之捉虫记

    全局变量 写MapReduce程序时候,有时候须要用到全局变量,经常使用的全局变量实现由三种方式: 通过作业的Configuration传递全局变量.作业初始化的时候.conf.set(),须要的时候 ...