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间房间,并且满足可以从任何一 ...
随机推荐
- proteus仿真 引脚显示电平变化但不能显示波形
proteus仿真 引脚显示电平变化但不能显示波形 原来是没有选择通道问题,proteus默认优先使用A通道才会显示波形,如果优先使用B,C,D通道,需要选择...
- The following signatures couldn't be verified because the public key is not available 解决方法
今天试图把 deepin 的软件源加到我到 Ubuntu 16.04 中去. 在 deepin wiki 上看到一个教程. 在 /etc/apt/sources.list 中加上 deepin 的软件 ...
- HDU 4027 Can you answer these queries?(线段树区间开方)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- luogu3723 [AH2017/HNOI2017]礼物 【NTT】
题目 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是在她生日的前一天, ...
- 自己搭建了一个blog
https://svtt.sinaapp.com 利用JustWriting开源项目搭建的,不过还是有些许问题.但是考虑到自己的blog好处多多,暂且用着--有时间或者乐趣来了,自己再用wordpre ...
- 解决jsp在ios小屏手机下面滑动不流畅的问题
今天做好的静态文件发给后台改成jsp之后,发现原本流畅滑动的页面在iphone5下面变得一卡一卡的. 之后加上了 -webkit-overflow-scrolling: touch; 这个属性之后,成 ...
- 【10】react 之 react-router
1.1. 路由 路由:URL与处理器的映射. 浏览器当前的 URL 发生变化时,路由系统会做出一些响应,用来保证用户界面与 URL 的同步. 1.2. Router安装 npm i react-r ...
- spring rest 请求怎样添加Basic Auth请求頭
请自行揣摩代码 package com.hudai.platform.manager.util; import java.net.URI; import java.net.URISyntaxExcep ...
- 教你怎么使用Windows7系统自带的备份与还原的方法
原文发布时间为:2010-09-09 -- 来源于本人的百度文章 [由搬家工具导入] 继续单击“下一步”按钮,在其后界面中检查上述备份设置是否正确,如果不正确的话可以直接单击“取消”按钮,重新设置备份 ...
- DBus介绍
1. 介绍 DBus是一种桌面环境的进程间通讯(IPC)机制,有低时延.低消耗等优点 基于socket,提供了一对一的对等通讯:使用dbus-daemon作为后台进程时,可实现多对多通讯 由如下三个层 ...