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. Resize operation completed for file#

    Orale 12c RAC环境ALERT LOG中出现Resize operation completed for file# 查看数据库版本: BANNER CON_ID ------------- ...

  2. hibernate运行常见错误

    错误一: Exception in thread "main" org.hibernate.MappingException: Could not determine type f ...

  3. 【bzoj4699】树上的最短路(树剖+线段树优化建图)

    题意 给你一棵 $n$ 个点 $n-1$ 条边的树,每条边有一个通过时间.此外有 $m$ 个传送条件 $(x_1,y_1,x_2,y_2,c)$,表示从 $x_1$ 到 $x_2$ 的简单路径上的点可 ...

  4. vue中如何将时间对象转换成字符串

    借鉴element-admin中封装好的方法 import { parseTime } from '@/utils'// 在utils目录下的index.js文件中,方法如下 /** * Parse ...

  5. 【03】react 之 创建component

    React推出后,出于不同的原因先后出现三种定义react组件的方式,殊途同归:具体的三种方式: 函数式定义的无状态组件 es5原生方式React.createClass定义的组件 es6形式的ext ...

  6. Jquery : 上下滚动--单行 批量多行 文字图片翻屏【转】

    原文发布时间为:2010-02-01 -- 来源于本人的百度文章 [由搬家工具导入] 注:如果和左右滚动一起使用,则会出现冲突 一单行滚动(ad:http://www.gz138.com) <! ...

  7. [LeetCode] Find Peak Element 二分搜索

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  8. linux内核之系统调用nanosleep与pause()

    nanosleep()使得进程进入睡眠状态,指定时候后唤醒进程,sleep()基于其实现 asmlinkage long sys_nanosleep(struct timespec *rqtp, st ...

  9. 小记——关于Tilemap图块索引编码

    图集 地图 TileMap 导出的 .Tmx 文件记录了地图所有信息,其中编辑好的图块信息会存放在每个图层的 Data 节点下.以下是一个 10x10 的图层,可以看到,Data 节点记录了每个图块对 ...

  10. LeetCode OJ-- Generate Parentheses *

    https://oj.leetcode.com/problems/generate-parentheses/ 输入n产生n个( ,n个 )组成的所有合法的括号组合. 现在纸上画画,找到规律: 1.每一 ...