ZOJ 3329 Problem Set (期望dp)
One Person Game
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
code
#include<cstdio>
#include<algorithm>
#include<cstring> using namespace std;
const int N = ;
double p[N],x[N],y[N],t; int main() { int T,n,k1,k2,k3,a,b,c,sum;
scanf("%d",&T);
while (T--) {
scanf("%d%d%d%d%d%d%d",&n,&k1,&k2,&k3,&a,&b,&c);
memset(p,,sizeof(p));
memset(x,,sizeof(x));
memset(y,,sizeof(y)); t = 1.0/(double(k1*k2*k3));
sum = k1+k2+k3; for (int i=; i<=k1; ++i)
for (int j=; j<=k2; ++j)
for (int k=; k<=k3; ++k)
if (i!=a || j!=b || k!=c) p[i+j+k] += t; for (int i=n; i>=; --i) {
x[i] = t;y[i] = 1.0;
for (int k=; k<=sum; ++k)
x[i] += p[k]*x[i+k],y[i] += p[k]*y[i+k];
} printf("%.15lf\n",y[]/(1.0-x[])); }
return ;
}
ZOJ 3329 Problem Set (期望dp)的更多相关文章
- poj 2096 , zoj 3329 , hdu 4035 —— 期望DP
题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...
- poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP
poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...
- ZOJ Problem Set - 3822Domination(DP)
ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...
- ZOJ 3822 Domination 期望dp
Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...
- poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)
Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...
- [CF697D]Puzzles 树形dp/期望dp
Problem Puzzles 题目大意 给一棵树,dfs时随机等概率选择走子树,求期望时间戳. Solution 一个非常简单的树形dp?期望dp.推导出来转移式就非常简单了. 在经过分析以后,我们 ...
- B20J_1419_Red Is Good_期望DP
B20J_1419_red is good_期望DP 题意:有R张红牌和B张黑牌,一张一张地翻牌,翻到红牌得到1美元,黑牌则付出1美元.可以随时停止翻牌,在最优策略下平均能得到多少钱. 分析:期望DP ...
- 概率和期望dp
概率和期望dp 概率和期望好神啊,完全不会. 网上说概率要顺着推,期望要逆着推,然而我目前做的概率期望题正好都与此相反2333 概率: 关于概率:他非常健康 初中概率题非常恐怖.现在来思考一道题: ...
- poj2096 Collecting Bugs[期望dp]
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 5394 Accepted: 2670 ...
随机推荐
- Azure 3 月新公布
Azure 3 月新发布:Power BI Embedded,R Server 和 IoT 套件预测性维护预配置解决方案正式发布,ExpressRoute 部署变更,以及计量名称变更 Power BI ...
- Python扩展包
Python扩展包 1.NumPy NumPy提供了多种python本身不支持的多种集合,有list.ndarray和ufunc. list 更加灵活的数组,支持多维,数据可不同型,存储数量远大于ar ...
- 在android开发中如何使用JavaMail程序
javaMail,是提供给开发者处理电子邮件相关的编程接口.它是Sun发布的用来处理email的API.它可以方便地执行一些常用的邮件传输.我们可以基于JavaMail开发出类似于Microsoft ...
- UE4工具
COMMON CONTAINERS TARRAY (Engine\Source\Runtime\Core\Public\Containers\Array.h) TSET (Engine\Source\ ...
- 爬虫第一篇基本库的使用——urllib
在Python2中有urllib2和urllib3两个库来实现请求的发送,在Pyhon3中则统一为urllib. urilib包含以下4个模块 request:最基本的请求模块,可以用来实现请求的发送 ...
- 【转载】#437 - Access Interface Members through an Interface Variable
Onece a class implementation a particular interface, you can interact with the members of the interf ...
- Firefox浏览器 页面滑动卡帧问题
在设置里关闭"平滑滚动"选项即可,猎豹似乎没有,遭黑
- url获取MVC域,action,controller的方法
域:filterContext.RequestContext.RouteData.DataTokens["area"] 控制器:filterContext.RequestConte ...
- 使用selenium grid的hub做分发,且可查看分发后的服务器IP地址
背景:借助selenium 的grid做分布式运行,进行分发任务,(目前不做多浏览器的操作,只对谷歌浏览器进行操作) 目前在A服务器(http://10.40.6.24:4444)上注册了一个hub, ...
- java 生成12位随机数,解决The literal 9999999999999 of type int is out of range 问题
原本想这样产生一个随机数,但是你会看到,只要数字超过了9位数,就会出问题,提示“The literal 1000000000000 of type int is out of range” 解决方式是 ...