[BZOJ2318][SPOJ4060]Game with probability Problem 概率DP
来源:互联网 发布:网络打印机ip 编辑:程序博客网 时间:2024/05/16 23:36
设f[i]为还剩i个石子,A为先手,A获胜的概率;
设g[i]为还剩i个石子,A为后手,A获胜的概率。
先不管p,q。设当有i个石子时,A取走的概率为x,B取走的概率为y。
那么f[i]=x* g[i-1]+(1-x)* g[i];g[i]=y* f[i-1]+(1-y)* f[i]。
联立解得f[i]=(x* g[i-1]+(1-x)* y* f[i-1])/(1-(1-x)* (1-y));g[i]=(y* f[i-1]+(1-y) * x* g[i-1])/(1-(1-x) * (1-y))。
现在可以看出,x和y的取值取决于f[i-1]和g[i-1]的大小关系。
若f[i-1]>g[i-1],那么 x=1-p,y=1-q;
否则x=p,y=q。
奇技淫巧:n很大的时候概率不怎么变,n=min(n,1000)即可。
代码:
#include<iostream>#include<cstdio>using namespace std;double f[1010],g[1010],p,q,x,y;int n;int main(){ int ca; scanf("%d",&ca); while(ca--) { scanf("%d%lf%lf",&n,&p,&q); n=min(n,1000); f[0]=0;g[0]=1; for(int i=1;i<=n;i++) { if(f[i-1]>g[i-1]) x=1-p,y=1-q; else x=p,y=q; f[i]=((1-x)*y*f[i-1]+x*g[i-1])/(1-(1-y)*(1-x)); g[i]=((1-y)*x*g[i-1]+y*f[i-1])/(1-(1-y)*(1-x)); } printf("%.6lf\n",f[n]); } return 0;}
阅读全文
0 0
- 【BZOJ2318】【spoj4060】game with probability Problem 概率DP
- [BZOJ2318]Spoj4060 game with probability Problem(概率dp)
- 【bzoj2318】Spoj4060 game with probability Problem 概率dp
- [BZOJ2318][SPOJ4060]Game with probability Problem 概率DP
- bzoj2318 Spoj4060 game with probability Problem
- 【bzoj2318】 Spoj4060 game with probability Problem
- 【bzoj2318】Spoj4060 game with probability Problem
- 概率DP Spoj4060 game with probability Problem
- 【BZOJ】【P2318】【Spoj4060 game with probability Problem】【题解】【概率DP】
- bzoj 2318: Spoj4060 game with probability Problem (概率与期望DP)
- 2318: Spoj4060 game with probability Problem|概率与期望
- BZOJ_P2318 SPOJ4060 game with probability Problem(概率动态规划)
- 【BZOJ 2318】Spoj4060 game with probability Problem 概率
- [BZOJ 2318]Spoj4060 game with probability Problem:概率
- BZOJ 2318: Spoj4060 game with probability Problem 概率
- bzoj2318Spoj4060 game with probability Problem 期望DP
- Game with probability Problem
- Codeforces 482C Game with Strings(dp+概率)
- 重磅 | 机智云平台荣膺“墨提斯奖”智能硬件开放平台创新奖
- Apache Avro使用入门指南
- mysql性能
- Plot Learning Rate
- RabbitMQ基础概念详细介绍
- [BZOJ2318][SPOJ4060]Game with probability Problem 概率DP
- 10月集训test15
- BZOJ1037(ZJOI2008)[生日聚会Party]--DP
- BeanFactory与ApplicationContext
- 如何判断链表中是否有环
- 链表
- 52- C++ 中的抽象类和接口
- 解决golang.org/x包无法下载的问题
- 【SSM框架整合】配置文件的配置