[LightOJ 1274] Beating the Dataset (期望DP)
来源:互联网 发布:关键词优化在哪里 编辑:程序博客网 时间:2024/05/18 19:45
LightOJ - 1274
题目等价于,给定一个开头为 1的 01串,
求其中相邻两个字符不相等的期望对数
一开始煞笔了,其实 YES和 NO的个数是可以直接算出来的
算出来之后,设
下一位出现 0或 1的概率可以用剩下除以后面的位数得到
如果下一位与当前位不同,期望加 1,否则不加
#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <cctype>#include <map>#include <set>#include <queue>#include <bitset>#include <string>using namespace std;typedef pair<int,int> Pii;typedef long long LL;typedef unsigned long long ULL;typedef double DBL;typedef long double LDBL;#define MST(a,b) memset(a,b,sizeof(a))#define CLR(a) MST(a,0)#define SQR(a) ((a)*(a))#define PCUT puts("----------")const int maxn=5e3+10;int N,S;DBL dp[2][2][maxn];int main(){ #ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); #endif int T; scanf("%d", &T); for(int ck=1; ck<=T; ck++) { scanf("%d%d", &N, &S); int A=S-2*N, B=3*N-S; CLR(dp); for(int i=N-1; i>=1; i--) { int cur=i&1, nxt=(i+1)&1; CLR(dp[cur]); for(int j=max(0, i-B); j<=i && j<=A; j++) { DBL pa = (DBL)(A-j)/(N-i), pb = (DBL)(B-(i-j))/(N-i); dp[cur][0][j] = pa*(dp[nxt][1][j+1] + 1) + pb*dp[nxt][0][j]; dp[cur][1][j] = pa*dp[nxt][1][j+1] + pb*(dp[nxt][0][j] + 1); } } DBL ans = A*dp[1][1][1]/N + B*(dp[1][0][0]+1)/N; printf("Case %d: %.7f\n", ck, ans); } return 0;}
0 0
- LightOJ-1274 Beating the Dataset(期望dp)
- [LightOJ 1274] Beating the Dataset (期望DP)
- 【LightOJ 1274】Beating the Dataset(概率DP)
- LightOJ 1274 Beating the Dataset (概率dp)
- LightOJ 1274 Beating the Dataset
- 数学期望,I - Beating the Dataset,Light OJ 1274
- LightOJ1274---Beating the Dataset (概率dp)
- light oj 1274 - Beating the Dataset
- Light OJ 1274 Beating the Dataset (推公式)
- LightOJ 1030 - Discovering Gold (期望dp)
- 【LightOJ 1030】Discovering Gold(期望DP)
- LightOJ-1342 Aladdin and the Magical Sticks(期望dp)
- LightOJ 1038 - Race to 1 Again (期望dp)
- [LightOJ 1364] Expected Cards (高维期望DP)
- [Codeforces398B]Painting The Wall(期望dp)
- LightOJ - 1248 Dice (III) 期望 + dp
- 【期望dp】Lightoj 1027 A Dangerous Maze
- 【期望dp】LightOJ 1030 Discovering Gold
- 打开相机和获取相册图片后实现裁剪
- Android第二周(第三部分)-GridView和ScrollView
- Qt-命令模式
- 逆序输出单个数字
- 我相信,终有一天,我会变成自己喜欢的模样
- [LightOJ 1274] Beating the Dataset (期望DP)
- listagg小记录
- win32 Socket网络编程连接
- Web安全渗透
- Android加载动画系列——WifiLoadingAnim
- 指针强制转换
- 【Linux】可重入函数和线程安全的区别与联系
- LINUX集群搭建必备:nat模式设置静态ip,达到上网与主机相互通信
- 设计资源库