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. 软工实践第八次作业——UML设计

    本次作业博客 团队组成 临时组长:何裕捷 组员:蔡子阳,陈德斌,胡青元,李麒,高裕翔,王焕仁,黄培鑫 UML 用例图 描述的部分: 1 这里是用户个人管理系统的用例图 面临的问题: 1 面临用户登录注 ...

  2. Kotlin-Not enough information to infer parameter T in fun<T:View> findViewById(id: Int): T!

    代码改变世界 错误: Type inference failed : Not enough information to infer parameter T in fun<T:View> ...

  3. 论文笔记(一)Re-ranking by Multi-feature Fusion with Diffusion for Image Retrieval

    0x00 预备知识 $\DeclareMathOperator{\vol}{vol}$ 无向图上的随机游走 无向图 $G=(V,E)$,边权函数 $w\colon V\times V \to R_+$ ...

  4. 版本控制——hg教程

    hg教程 引用来自官方网站的思维导图,来说明hg的使用规则:

  5. EclEmma Java Code Coverage for Eclipse

      1. 1EclEmma的介绍 一.EclEmma 简介: EclEmma是一个开源的软件测试工具(for eclipse),可以在编码过程中查看代码调用情况.也可以检测单覆盖率. 详见: http ...

  6. linux之eval

    1. eval command-line 其中command-line是在终端上键入的一条普通命令行.然而当在它前面放上eval时,其结果是shell在执行命令行之前扫描它两次.如: pipe=&qu ...

  7. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---33

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  8. Ubuntu14.04 LTS安装docker

    有以下几种方式: 1. 通过系统自带包安装(可能不是最新版) $ sudo apt-get update $ sudo apt-get install -y docker.io $ sudo ln - ...

  9. php --图片加图片水印

    最近在做一个视频网站需要视频有一个封面图片,但是不能是普通的图片,能让别人一眼看出来是 视频,所以我就在图片上面加了视频播放器的那种水印,具体代码如下: <?php/** * 图片加水印(适用于 ...

  10. TeamViewer下载地址

    http://www.teamviewer.com/zhCN/download/linux.aspx Ubuntu配置远程访问的xrdp协议和teamviewer软件 先启用远程设置:System-& ...