概率期望相关

概率期望相关

预备知识

  • P(A):AE(A):A
  • A,E(A)=1P(A)(AB)
  • ABE(A+B)=E(A)+E(B)E(AB)=E(A)E(B)E(A/B)=E(A)/E(B)
  • :P(A)=iP(A|Bi)P(Bi)(P(A|B):BA)
  • E(A|B=bi)B=biA
  • :
    E(E(A|B))====iP(B=bi)E(A|B=bi)iP(B=bi)jajP(B=biA=aj)P(B=bi)ijajP(B=biA=aj)E(A)

    E(A)=iP(B=bi)E(A|B=bi)

递推或DP解决

离散型期望

一道简单题

题目大意

n,,n

题解

,k,k+1
,nnk()
ans=nni=11n

[BZOJ1426] 收集邮票

http://www.lydsy.com/JudgeOnline/problem.php?id=1426

题目大意

n,k(k)k,n

题解

f[i]:i
g[i]:i
f[i]=f[i1]+nni+1
g[i]=g[i1]+(f[i1]+1)ni+1n+(f[i1]+1+f[i1]+2)i1nni+1n
()
g[i]=g[i1]+f[i1]nni+1+(nni+1)2

CODE

[UVA11762] Race to 1

题目大意

n,np,p|nn/=p,,n1,

题解

dp[i]:n=idp[i]i1
sum[i]:1 ~ i

dp[i]=dp[i]pjisum[i]+pjidp[ipj]1sum[i]+1

g(i):ii
dp[i]=dp[i]sum[i]g[i]sum[i]+pjidp[ipj]1sum[i]+1

g[i]sum[i]dp[i]=pjidp[ipj]1sum[i]+1

dp[i]=pjidp[ipj]+sum[i]g[i]

然后记忆化搜索一下

[HDU4405] Aeroplane chess

http://acm.hdu.edu.cn/showproblem.php?pid=4405

题目大意

0{1,2,3,4,5,6},1,,,>=n

题解

DP,,
,n<=0
CODE

[UVA10529] Dumb Bones

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1470

题目大意

n,pl,pr(1plpr>0)
n

题解

,[1..i1][i+1..n],i,[1..i1]E1,[i+1..n]E2
E1+E2+1
11plpr

11plpr1=pl+pr1plpr
,pl+pr1plprplpl+pr=pl1plpr,pr1plpr
E=pl1plprE1+pr1plprE2+11plpr
,E1+E2
dp[i]:i
dp[i]=min(dp[i],1pr1plprdp[j]+1pl1plprdp[ij1]+11plpr)
dp()O(N2)O(N)
CODE

[51NOD1670] 打怪兽

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1670

题目大意

n([0,n1]),0,>=,

题解

dp[i]:i
sum[i]:<=i
方案也是满足概率条件的
有多大概率死亡就有多大概率的方案就此终结掉
dp[i]=dp[i1]sum[i1]i+1ni+1
dp[i1]dp[i]:i1
ans=(dp[i1]dp[i])(i1)=dp[i]
,,()
CODE

[POJ2096] Collecting Bugs

http://poj.org/problem?id=2096

题目大意

s,n(),
n

题解

dp[i,j]:i,j,
dp[i,j]=dp[i+1,j]sisjn+dp[i,j+1]njnis+dp[i+1,j+1]sisnjn+dp[i,j]isjn
dp[i,j]ij?
dp[s,n],0,,
CODE

[SRM448 DIV1 250pt] TheBoredomDivOne

题目大意

nm,n+m2,n+m

题解

dp[i]:n+mi,i
$dp[i]=dp[i-1]\frac{i(n+m-i)}{C_{n+m}^{2}}+dp[i-2]\frac{C_{i}^{2}}{C_{n+m}^2}+dp[i]\frac{C_{n
+m-i}^2}{C_{n+m}^{2}}+1$
CODE

[UVA11021] Tribles

http://cojs.tk/cogs/problem/problem.php?pid=1487

题目大意

k,,Pii(),m(m)

题解

,1
dp[i]:i
dp[i]=n1j=0pj(dp[i1])j
,idp[i1]
ans=(dp[m])k
CODE
这题与下题有相似之处
他们都枚举的是第一次而不是最后一次,因为最后一次已经被前面限制住了,而第一次是没有的

[BZOJ1419]/[SRM420 Div1 500pt] Red is good

http://www.lydsy.com/JudgeOnline/problem.php?id=1419

题目大意

n+1m1,,,

题解

,,
0,
dp[i,j]:i+1j1
0,i+1,j1,+1ii+j1ji+j
dp[i,j]=max(0,(dp[i1,j]+1)ii+j+(dp[i,j1]1)ji+j)
dp[0,j]=0   dp[i,0]=i
CODE

[Noi2005] 聪聪和可可

http://www.lydsy.com/JudgeOnline/problem.php?id=1415

题目大意

给定一张无向图,两个点A和B,每次A都向着离B最近的方向走,如果有两个点都可以,走编号小的那个,A如果走一次没遇到可以在这个时间内再走一步,B每次可以留在原来的点或者等概率走相邻的点,询问A遇到B的期望时间

题解

,O(N2)path[i,j]:Ai,Bj,A
du[i]:i
dp[i,j]:Ai,Bj

dp[i,j]=k=jjdp[path[path[i,j],j],k]du[j]+1+1

dp[i,i]=0
path[i,j]=jpath[path[i,j],j]=jdp[i,j]=1

CODE

[BZOJ4204] 取球游戏

http://www.lydsy.com/JudgeOnline/problem.php?id=4204

题目大意

iai,(i[1,n]),m,,s,s<n,s=s+1,s=1
k

题解

dp[i]:i
dp[i]=dp[i]+dp[i1]1mdp[i]1m
dp[i]=dp[i1]1m+dp[i]m1m
klogk
,n=1000,

dp[n]dp[n1]dp[1]=(m1)/m01/m1/m(m1)/m001/m000(m1)/mkdp[n]dp[n1]dp[1]
(2),,O(N2logk)
tempmatrix[i]+=matrix[j]matrix[(ji+n) % n+1]
CODE

[BZOJ2318] [SPOJ4060] game with probability Problem

http://www.lydsy.com/JudgeOnline/problem.php?id=2318

题目大意

n,A,,,
Ap,Bq
A

题解

f[i]:iA
g[i]:iA
A,A,f[i]=pg[i1]+(1p)g[i]
A,B,g[i]=qf[i1]+(1q)f[i]
f[i]=pg[i1]+(1p)qf[i1]1(1p)(1q)
g[i]=qf[i1]+(1q)pg[i1]1(1p)(1q)
,A(

你可能感兴趣的:(动态规划—概率DP)