zoj3329--One Person Game(概率dp第六弹:形成环的dp,带入系数,高斯消元)
One Person Game
Time Limit: 1 Second Memory Limit: 32768 KB Special Judge
There is a very simple and interesting one-person game. You have 3 dice, namely Die1, Die2 and Die3. Die1 has K1 faces. Die2 has K2 faces. Die3 has K3 faces.
All the dice are fair dice, so the probability of rolling each value, 1 to K1, K2, K3 is exactly 1 / K1, 1 / K2 and
1 / K3. You have a counter, and the game is played as follow:
- Set the counter to 0 at first.
- Roll the 3 dice simultaneously. If the up-facing number of Die1 is a, the up-facing number of Die2 is b and the
up-facing number of Die3 is c, set the counter to 0. Otherwise, add the counter by the total value of the 3 up-facing numbers. - If the counter's number is still not greater than n, go to step 2. Otherwise the game is ended.
Calculate the expectation of the number of times that you cast dice before the end of the game.
Input
There are multiple test cases. The first line of input is an integer T (0 < T <= 300) indicating the number of test cases. Then T test cases
follow. Each test case is a line contains 7 non-negative integers n, K1, K2, K3, a, b, c (0
<= n <= 500, 1 < K1, K2, K3 <= 6, 1 <= a <= K1,
1 <= b <= K2, 1 <= c <= K3).
Output
For each test case, output the answer in a single line. A relative error of 1e-8 will be accepted.
Sample Input
2
0 2 2 2 1 1 1
0 6 6 6 1 1 1
Sample Output
1.142857142857143
1.004651162790698
题目大意:给出了k1,k2,k3三个筛子。当k1 == a k2 == b k3 == c时分数归零,否则累加,问当总和到n以上须要的次数期望
状态方程非常好写。dp[i]代表由i到n以上须要的次数,dp[i] = ∑(p[j]*dp[i+j])+q*dp[0] + 1。p[j]代表掷出和为j的概率,q为归零的概率。可是为问题出现了,在状态方程中有dp[0]这是我们要求解的值。所以要带入系数dpa[],dpb[],dp[i] = dpa[i] + dpb[i]*dp[0] ;
最后求解出dp[0] = dpa[0] + dpb[0]*dp[0],能够解除dp[0];
dp[i] = dpa[i] + dpb[i]*dp[0] = ∑(p[j]*dp[i+j])+ q*dp[0]+1;
得到dpa[i] = ∑( p[j]*dpa[i+j] ) + 1 ; dpb[i] = ∑( p[j]*dpb[i+j] ) + q ;
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
double p[20] , q , cnt ;
double dpa[600] , dpb[600] ;
int main()
{
int t , n , m , i , j , k , l , k1 , k2 , k3 , a , b , c ;
scanf("%d", &t);
while(t--)
{
scanf("%d %d %d %d %d %d %d", &n, &k1, &k2, &k3, &a, &b, &c);
memset(p,0,sizeof(p));
memset(dpa,0,sizeof(dpa));
memset(dpb,0,sizeof(dpb));
p[a+b+c] = -1 ;
cnt = 0 ;
m = k1 + k2 + k3 ;
for(i = 1 ; i <= k1 ; i++)
for(j = 1 ; j <= k2 ; j++)
for(k = 1 ; k <= k3 ; k++)
{
p[i+j+k] += 1.0 ;
cnt += 1.0 ;
}
for(i = 3; i <= m ; i++)
p[i] /= cnt ;
q = 1.0 / cnt ;
for(i = n ; i >= 0 ; i--)
{
dpa[i] = 1.0 ; dpb[i] = q ;
for(j = 3 ; j <= k1+k2+k3 ; j++)
{
dpa[i] += p[j]*dpa[i+j] ;
dpb[i] += p[j]*dpb[i+j] ;
}
}
printf("%.10lf\n", dpa[0]/(1-dpb[0]));
}
return 0;
}
zoj3329--One Person Game(概率dp第六弹:形成环的dp,带入系数,高斯消元)的更多相关文章
- 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)
题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...
- BZOJ 3143: [Hnoi2013]游走 概率与期望+高斯消元
Description 一个无向连通图,顶点从1编号到N,边从1编号到M.小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点的某条边,沿着这条边走到下一个顶点,获 ...
- 【概率DP/高斯消元】BZOJ 2337:[HNOI2011]XOR和路径
2337: [HNOI2011]XOR和路径 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 682 Solved: 384[Submit][Stat ...
- BZOJ 3640: JC的小苹果 [概率DP 高斯消元 矩阵求逆]
3640: JC的小苹果 题意:求1到n点权和\(\le k\)的概率 sengxian orz的题解好详细啊 容易想到\(f[i][j]\)表示走到i点权为j的概率 按点权分层,可以DP 但是对于\ ...
- BZOJ 2337: [HNOI2011]XOR和路径 [高斯消元 概率DP]
2337: [HNOI2011]XOR和路径 题意:一个边权无向连通图,每次等概率走向相连的点,求1到n的边权期望异或和 这道题和之前做过的高斯消元解方程组DP的题目不一样的是要求期望异或和,期望之间 ...
- BZOJ 3270: 博物馆 [概率DP 高斯消元]
http://www.lydsy.com/JudgeOnline/problem.php?id=3270 题意:一张无向图,一开始两人分别在$x$和$y$,每一分钟在点$i$不走的概率为$p[i]$, ...
- BZOJ_1778_[Usaco2010 Hol]Dotp 驱逐猪猡_概率DP+高斯消元
BZOJ_1778_[Usaco2010 Hol]Dotp 驱逐猪猡_概率DP+高斯消元 题意: 奶牛们建立了一个随机化的臭气炸弹来驱逐猪猡.猪猡的文明包含1到N (2 <= N <= 3 ...
- LightOJ 1151 Snakes and Ladders(概率DP + 高斯消元)
题意:1~100的格子,有n个传送阵,一个把进入i的人瞬间传送到tp[i](可能传送到前面,也可能是后面),已知传送阵终点不会有另一个传送阵,1和100都不会有传送阵.每次走都需要掷一次骰子(1~6且 ...
- 【BZOJ 2337】 2337: [HNOI2011]XOR和路径(概率DP、高斯消元)
2337: [HNOI2011]XOR和路径 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1170 Solved: 683 Description ...
- BZOJ3270: 博物馆【概率DP】【高斯消元】
Description 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博物馆.这座博物馆有着特别的样式.它包含由m条走廊连接的n间房间,并且满足可以从任何一 ...
随机推荐
- 兼容浏览器 回车键 keydown事件
$("body").keydown(function(event){ if(event.keyCode==13){ //body } }); 重点:$("bo ...
- 【转】Unity3D研究院之两种方式播放游戏视频
http://www.xuanyusong.com/archives/1019 Unity3D中播放游戏视频的方式有两种,第一种是在游戏对象中播放,就好比在游戏世界中创建一个Plane面对象,摄像 ...
- 通过TCP实现文件传输
import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.In ...
- MyEclipse生成get/set注释
我的外网链接 http://yezi-0016.iteye.com/blog/2290421
- Databus架构分析与初步实践
简介 Databus是一个低延迟.可靠的.支持事务的.保持一致性的数据变更抓取系统.由LinkedIn于2013年开源.Databus通过挖掘数据库日志的方式,将数据库变更实时.可靠的从数据库拉取出来 ...
- Jury Compromise(poj 1015)
描述在遥远的国家佛罗布尼亚,嫌犯是否有罪,须由陪审团决定.陪审团是由法官从公众中挑选的.先随机挑选n个人作为陪审团的候选人,然后再从这n个人中选m人组成陪审团.选m人的办法是: 控方和辩方会根据对候选 ...
- 洛谷 [P1608] 最短路计数
最短路计数模版 本题要注意重边的处理 #include <iostream> #include <cstdio> #include <algorithm> #inc ...
- 【SPOJ61】Brackets(线段树)
题意:给出一个括号序列,要求维护两种操作: 1.将第x位上的括号取反 2.查询当前整个括号序列是否匹配 n<=3e4 思路:线段树维护区间内没有匹配的左右括号数量 pushup时t[p].r=t ...
- 背景.jpg
- 使用T4模板创建一个例子
1.创建项目,添加新项,名称处填写Messages.tt,如下图: 添加后,Messages.tt文件内容如下: <#@ template debug="false" hos ...