
概率DP
芋智波佐助
菜鸟一只
展开
-
Light OJ 1248 - Dice (III) 概率DP
n个面的骰子 求每个面至少扔到一次的期望值设dp[i]为已经扔了i个不同面的期望值 dp[n] = 0 求dp[0]因为dp[i]为还需要扔i个不同的面 每次可能扔中已经扔过的面或者没有扔到过的面2中情况所以dp[i] = (i/n)*dp[i] + (n-i)/n*dp[i+1] +1 等号2边都有dp[i] 移项得dp[i] = dp[i+1]+n/(n-i) #inclu原创 2014-10-09 12:43:01 · 1666 阅读 · 0 评论 -
Light OJ 1317 Throwing Balls into the Baskets 概率DP
n个人 m个篮子 每一轮每个人可以选m个篮子中一个扔球 扔中的概率都是p 求k轮后所有篮子里面球数量的期望值根据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[n]*n 记为w其中dp[i]为i个人扔中的概率 dp[i] = C(n, i)*p^i*(1-p)^(n-i) 最终答案为w*k#include #include using names原创 2014-10-08 21:33:45 · 1120 阅读 · 0 评论 -
ZOJ 3329 One Person Game 带环的概率DP
每次都和e[0]有关系 通过方程消去环dp[i] = sigma(dp[i+k]*p)+dp[0]*p+1dp[i] = a[i]*dp[0]+b[i]dp[i] = sigma(p*(a[i+k]*dp[0]+b[i+k]))+dp[0]*p+1a[i] = sigma(a[i+k]*p)+pb[i] = sigma(b[i+k]*p)+1#include #inc原创 2014-10-02 23:28:08 · 926 阅读 · 0 评论 -
UVa 10828 Back to Kernighan-Ritchie 高斯消元+概率DP
题目来源:UVa 10828 Back to Kernighan-Ritchie题意:从1开始 每次等概率从一个点到和他相邻的点 有向 走到不能走停止 求停止时每个点的期望思路:写出方程消元 方程有唯一解 多解 无解的情况 有环 一直再环里无法停止算无穷大 从1不能到的点期望为0#include #include #include #include #include usin原创 2014-06-21 14:30:32 · 1358 阅读 · 0 评论 -
UVa 11021 Tribles / 概率DP
k只麻球 每活一天就会死 死之前有pi的概率生出i只麻球 求m天死光的的概率f[i] = p0 + p1*dp(i-1) + p2*dp(i-1)^2+....+pn-1*dp(i-1)^n-1好像是倒着推的pj*dp(i-1)^j 表示1个麻球生了j个麻球在i-1天后死光 1个麻球在i-1天死的概率为dp(i-1) j个麻球就是j个dp(i-1)相乘#include #incl原创 2014-02-05 19:21:22 · 1138 阅读 · 0 评论 -
UVa 11762 Race to 1 / 概率DP
公式f(x) = 1+f(x)*(1-g(x)/p(x))+ f(x/y)/p(x)p(x)是不超过x的素数的个数g(x)是p(x)个素数中是x因子的个数然后移项(和我上次做的那一题差不多)#include #include const int maxn = 1000010;int vis[maxn];int prime[maxn];int prime_cnt;dou原创 2014-02-05 15:10:52 · 1048 阅读 · 0 评论 -
UVa 11468 Substring AC自动机+概率DP
题目来源:UVA 11468 Substring题意:求不包含任意一个模式串的长度为l的文本串的概率 给出可以使用的字符的种类及其概率思路:AC自动机+概率DP #include #include #include using namespace std;const int maxnode = 20*22;const int size = 66;int ch[maxn原创 2014-04-18 14:25:27 · 1054 阅读 · 0 评论