链接:

#include <stdio.h>
int main()
{
puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/46467899");
}

题解:

fi 表示剩 i 个石头、 A 先手的获胜概率。

gi 表示剩 i 个石头、 A 后手的获胜概率。

假设想选,对于 fi:

有 p 的概率进入 gi−1 ;有 1−p 的概率进入 gi

所以 fi=p∗gi−1+(1−p)∗gi

假设想选。对于 g(i):

有 q 的概率进入 fi−1 ;有 1−q 的概率进入 fi

所以 gi=q∗fi−1+(1−q)∗fi

整理得:

fi=p∗gi−1+(1−p)∗q∗fi−11−(1−p)∗(1−q)

gi=q∗fi−1+(1−q)∗p∗gi−11−(1−p)∗(1−q)

然后剩 i 个石头时A的想不想选的意愿与 fi−1、gi−1 的大小关系有关。

fi−1>gi−1 都不想选。

fi−1<gi−1 都想选。

然后对于不想选的情况。那么 p=1−p,q=1−q 即可了。

然而这样就没法用矩阵乘法了。

就须要黑科技,,当n非常大时,事实上概率已经基本不动了。。让n=min(n,1000)就好了Qwq。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1010
using namespace std;
double f[N],g[N],p,q; int main()
{
int i,T,n;
for(scanf("%d",&T);T--;)
{
scanf("%d",&n),n=min(n,1000);
scanf("%lf%lf",&p,&q);
f[0]=0,g[0]=1;
for(i=1;i<=n;i++)
{
if(f[i-1]>g[i-1])p=1-p,q=1-q;
f[i]=(p*g[i-1]+(1-p)*q*f[i-1])/(1-(1-p)*(1-q));
g[i]=(q*f[i-1]+(1-q)*p*g[i-1])/(1-(1-p)*(1-q));
if(f[i-1]>g[i-1])p=1-p,q=1-q;
}
printf("%.6lf\n",f[n]);
}
return 0;
}

【BZOJ2318】【spoj4060】game with probability Problem 概率DP的更多相关文章

  1. BZOJ 2318: Spoj4060 game with probability Problem( 概率dp )

    概率dp... http://blog.csdn.net/Vmurder/article/details/46467899 ( from : [辗转山河弋流歌 by 空灰冰魂] ) 这个讲得很好 , ...

  2. BZOJ 2318: Spoj4060 game with probability Problem (概率dp)(博弈论)

    2318: Spoj4060 game with probability Problem Description Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果 ...

  3. 【bzoj2318】Spoj4060 game with probability Problem 概率dp

    题目描述 Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果正面朝上,则从n个石子中取出一个石子,否则不做任何事.取到最后一颗石子的人胜利.Alice在投掷硬币时有 ...

  4. 【BZOJ2318】Spoj4060 game with probability Problem 概率

    [BZOJ2318]Spoj4060 game with probability Problem Description Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬 ...

  5. BZOJ2318: Spoj4060 game with probability Problem

    #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #i ...

  6. 嘴巴题8 BZOJ2318: Spoj4060 game with probability Problem

    Time Limit: 1 Sec Memory Limit: 128 MB Submit: 555 Solved: 273 [Submit][Status][Discuss] Description ...

  7. 【BZOJ 2318】 2318: Spoj4060 game with probability Problem(概率DP)

    2318: Spoj4060 game with probability Problem Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 371  Sol ...

  8. 2318: Spoj4060 game with probability Problem

    2318: Spoj4060 game with probability Problem Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 356  Sol ...

  9. Bzoj 2318 Spoj4060 game with probability Problem

    2318: Spoj4060 game with probability Problem Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 524  Sol ...

随机推荐

  1. I.MX6 bq27441 driver hacking

    /************************************************************************* * I.MX6 bq27441 driver ha ...

  2. 关于Azure存储账户中存储虚拟机VHD文件的注意事项

     Joy Qiao from MSFT  Thu, Mar 12 2015 3:16 PM 我们在使用Azure时经常都会在Azure存储账户中放一些文件,包括Azure虚机的VHD文件也都是放在存储 ...

  3. Java [Leetcode 273]Delete Node in a Linked List

    题目描述: Write a function to delete a node (except the tail) in a singly linked list, given only access ...

  4. 将你的Asp.NET应用程序嵌入到SharePoint

    转:http://www.cnblogs.com/Clank/archive/2007/05/21/754073.html 为什么要将Asp.net应用程序嵌入到SharePoint?这个我们不讨论! ...

  5. HDU 2289 Cup

    Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.3

    Let $\scrM$ be a $p$-dimensional subspace of $\scrH$ and $\scrN$ its orthogonal complement. Choosing ...

  7. 进程通信之一 使用WM_COPYDATA C++及C#实现 z

    原文地址:http://blog.csdn.net/morewindows/article/details/6804157 进程间通信最简单的方式就是发送WM_COPYDATA消息.本文提供C++及C ...

  8. 在Sql Server 查询分析器里使用事务

    declare @updatecount int begin TRAN DECLARE @tbid INTSELECT @tbid=iMax FROM tbID WHERE strName='ipcc ...

  9. 验证码生成-->漂亮啊

    验证码不用输出太多的HTML代码,直接创建一个一般处理程序,直接上代码 public class VCode : IHttpHandler { HttpContext context = null; ...

  10. bzoj 3197 [Sdoi2013]assassin(Hash+DP+KM)

    Description Input Output Sample Input 4 1 2 2 3 3 4 0 0 1 1 1 0 0 0 Sample Output 1 HINT [思路] Hash,D ...