matlab赌徒输完问题,Gambler's Ruin(赌徒破产问题 概率论)

赌徒破产问题,做tc时遇到,顺便拿来好好研究下

问题如下:

一个赌徒有h枚金币,每次有概率a获得一枚金币或者概率(1-a)丢掉一枚金币,直到其所有的金币总数达到N或0则游戏结束,求赌徒最终赢得N枚金币的概率P(N|h)。

对于两个状态我们可以确定,即P(N|N)=1、P(N|0)=0。同时得出状态转移公式(概率的推导和普通的DP还是很不一样的,好好体会下):

P(N|h) = a*P(N|h+1) + (1-a)*P(N|h-1)

这类公式可以表示为二阶线性递归关系,其特征多项式为(自行百度):

x^2 - 1/a * x + (1-a)/a = 0

求出特征方程的根为1和r=(1-a)/a,针对a==1/2的情况需要特殊处理。得到公式的通解为:

P(N|h) = A*(1^h) + B*(r^h)

根据已知条件P(N|N)=1、P(N|0)=0得:

1 = A + B*(r^N)

0 = A + B

A = -1/(r^N - 1)、B = 1/(r^N - 1)

得到最终解 P(N|h) = (r^h - 1)/(r^N - 1)

但是当a==1/2时,特征方程有重根,因此这种情况下通解为

P(N|h) = A+B*h

A = 0、B=1/N

即 P(N|h) = h/N

再来看topcoder srm 667 div1 500的题

Problem Statement

There are N cats sitting around a circle. The cats are numbered 0 throughN-1 in clockwise order. Note that as they sit around a circle, catN-1 is adjacent to cat 0. The cats are playing a game and the winner will get a prize!

The game looks as follows:

There is a single ball. Initially, cat 0 holds the ball.

In each round of the game, the cat who

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值