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 Die1Die2 and Die3Die1 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 K1K2K3 is exactly 1 / K1, 1 / K2 and
1 / K3. You have a counter, and the game is played as follow:

  1. Set the counter to 0 at first.
  2. 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.
  3. 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 nK1K2K3abc (0
<= n <= 500, 1 < K1K2K3 <= 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,带入系数,高斯消元)的更多相关文章

  1. 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)

    题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...

  2. BZOJ 3143: [Hnoi2013]游走 概率与期望+高斯消元

    Description 一个无向连通图,顶点从1编号到N,边从1编号到M.小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点的某条边,沿着这条边走到下一个顶点,获 ...

  3. 【概率DP/高斯消元】BZOJ 2337:[HNOI2011]XOR和路径

    2337: [HNOI2011]XOR和路径 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 682  Solved: 384[Submit][Stat ...

  4. BZOJ 3640: JC的小苹果 [概率DP 高斯消元 矩阵求逆]

    3640: JC的小苹果 题意:求1到n点权和\(\le k\)的概率 sengxian orz的题解好详细啊 容易想到\(f[i][j]\)表示走到i点权为j的概率 按点权分层,可以DP 但是对于\ ...

  5. BZOJ 2337: [HNOI2011]XOR和路径 [高斯消元 概率DP]

    2337: [HNOI2011]XOR和路径 题意:一个边权无向连通图,每次等概率走向相连的点,求1到n的边权期望异或和 这道题和之前做过的高斯消元解方程组DP的题目不一样的是要求期望异或和,期望之间 ...

  6. BZOJ 3270: 博物馆 [概率DP 高斯消元]

    http://www.lydsy.com/JudgeOnline/problem.php?id=3270 题意:一张无向图,一开始两人分别在$x$和$y$,每一分钟在点$i$不走的概率为$p[i]$, ...

  7. BZOJ_1778_[Usaco2010 Hol]Dotp 驱逐猪猡_概率DP+高斯消元

    BZOJ_1778_[Usaco2010 Hol]Dotp 驱逐猪猡_概率DP+高斯消元 题意: 奶牛们建立了一个随机化的臭气炸弹来驱逐猪猡.猪猡的文明包含1到N (2 <= N <= 3 ...

  8. LightOJ 1151 Snakes and Ladders(概率DP + 高斯消元)

    题意:1~100的格子,有n个传送阵,一个把进入i的人瞬间传送到tp[i](可能传送到前面,也可能是后面),已知传送阵终点不会有另一个传送阵,1和100都不会有传送阵.每次走都需要掷一次骰子(1~6且 ...

  9. 【BZOJ 2337】 2337: [HNOI2011]XOR和路径(概率DP、高斯消元)

    2337: [HNOI2011]XOR和路径 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1170  Solved: 683 Description ...

  10. BZOJ3270: 博物馆【概率DP】【高斯消元】

    Description 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博物馆.这座博物馆有着特别的样式.它包含由m条走廊连接的n间房间,并且满足可以从任何一 ...

随机推荐

  1. PAT1032

    为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过105的正整数N,即参赛人数.随后N行,每行给出一位 ...

  2. (转)对称加密与非对称加密,以及RSA的原理

    一 概述 二对称加密和非对称加密 对称加密 非对称加密 区别 三RSA原理 整数运算 同余运算 当模数为合数n时 当模数为质数p的时候 离散对数问题 RSA原理 一 , 概述 在现代密码学诞生以前,就 ...

  3. 省选算法学习-插头dp

    插头dp?你说的是这个吗? 好吧显然不是...... 所谓插头dp,实际上是“基于连通性的状态压缩dp”的简称,最先出现在cdq的论文里面 本篇博客致力于通过几道小小的例题(大部分都比较浅显)来介绍一 ...

  4. log4j.xml配置文件详解

    一 log4j.xml 配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:c ...

  5. nodeJS学习(4)--- webstorm/...开发 NodeJS 项目-节1

    前提: 已安装好 IDE ,eg:webstorm/IDEA 2016.3 & 2017.1 nodeJS(含 npm 及 相应的模板等) 要用 webstorm 开发 NodeJS项目(we ...

  6. BZOJ 3876 支线剧情

    支线剧情 [故事背景] 宅男JYY非常喜欢玩RPG游戏,比如仙剑,轩辕剑等等.不过JYY喜欢的并不是战斗场景,而是类似电视剧一般的充满恩怨情仇的剧情.这些游戏往往都有很多的支线剧情,现在JYY想花费最 ...

  7. Javascript&Html-弹出窗口的屏蔽程序

    大多数的浏览器都内置了弹出窗口的屏蔽程序,即使没有内置此类屏蔽程序的浏览器,用户也可以安装Yahoo tool等带有内置屏蔽程序的应用工具. 结果就是用户可以将绝大多数弹出窗口屏蔽掉. 于是,再弹出窗 ...

  8. 易用的开源日志记录程序及其 .NET不用IIS实现预览站点工具

    原文发布时间为:2011-02-28 -- 来源于本人的百度文章 [由搬家工具导入] http://code.google.com/p/elmah/ (不需要改动任何的程序)、简单的配置(几行配置)、 ...

  9. MSClass (Class Of Marquee Scroll通用不间断滚动JS封装类) Ver 1.65

    原文发布时间为:2010-02-07 -- 来源于本人的百度文章 [由搬家工具导入] http://www.popub.net/script/MSClass.html/*MSClass (Class ...

  10. C# Log日志工具类

    using System; using System.Collections.Generic; using System.Text; using System.IO; public class Log ...