codeforces 351B B. Jeff and Furik(概率)
来源:互联网 发布:zookeeper 选举算法 编辑:程序博客网 时间:2024/06/05 11:26
题目链接:
codeforces 351B
题目大意:
给出一个游戏,先手选择一对相邻的数交换位置,后手随机找一对数,然后掷硬币决定是否交换,如果不能交换,那么就重新找。问大致序列有序的采取最优策略的布数的期望。
题目分析:
- 定义dp[i]表示减少i个逆序对的步数的期望。
dp[i]=1+1+dp[i−2]⋅0.5+dp[i−1+1]]⋅0.5 - 因为先手可以选择,所以它每次一定会采取操作减少一个逆序对。
- 我们得到dp[i] = 4 + dp[i-2],dp[0] = 0 , dp[1] = 1;
AC代码:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#define MAX 3007using namespace std;int n,a[MAX];int main ( ){ while ( ~scanf ( "%d" , &n ) ) { for ( int i = 0 ; i < n ; i++ ) scanf ( "%d" , &a[i] ); int m = 0; for ( int i = 1 ; i < n; i++ ) for ( int j = 0 ; j < i ; j++ ) if ( a[j] > a[i] ) m++; int ans = 0; if ( m&1 ) ans = 1 + m/2*4; else ans = m*2; printf ( "%.7f\n" , (double)ans ); }}
0 0
- codeforces 351B B. Jeff and Furik(概率)
- CodeForces 351B Jeff and Furik 概率DP 逆序对
- CodeForces 351 B.Jeff and Furik(概率DP)
- CodeForces 351B Jeff and Furik(YY题)
- B. Jeff and Furik----数学期望
- Codeforces Round #204 (Div. 1) B. Jeff and Furik 1月7日
- [CF 351B]Jeff and Furik[归并排序求逆序数]
- CodeForces #352B.Jeff and Periods
- CodeForces-352D Jeff and Furik(递推)
- B. Jeff and Periods
- B. Jeff and Periods
- Codeforces Round #204 (Div. 2) B. Jeff and Periods
- Codeforces Round #204 (Div. 2) B - Jeff and Periods
- CF#204DIV2:B. Jeff and Periods
- codeforces 167B Wizards and Huge Prize DP 概率
- Codeforces 167B Wizards and Huge Prize 概率dp(水
- codeforces B. Dreamoon and WiFi 组合数学求概率
- Codeforces 167B Wizards and Huge Prize 概率dp
- 线程死锁问题
- python中return与pass的区别
- java基础——break灵活应用
- hdu 5464 Clarke and problem dp
- 学习工具篇 - eclipse 中使用autotools plugins
- codeforces 351B B. Jeff and Furik(概率)
- Android:screenrecord录制屏幕录像
- Swift学习笔记14——初始化(Initialization)和析构(Deinitialization)其一
- GNU Autotools的使用方法
- 天声人語 20151005
- OSI七层协议各层功能及典型设备
- 语义化前段UI框架Semantic UI
- Android专项练习题
- SEnginx安全相关模块配置说明