ZOJ Problem Set - 3329(概率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
本题通过代换系数,化简后求系数。
一般形成环的用高斯消元法求解。但是此题都是和dp[0]相关。所有可以分离出系数。
dp[i]表示达到i还要掷几次的期望,每一项都和dp[0]有关,且可表示成dp[i]=A[i]*dp[0]+B[0];
所以只要求出dp[0]的系数A,B就可以求出dp[0]=B[0]/(1-A[0]);
dp[n] = dp[0]/k1/k1/k1+1;
然后递推可推出dp[0]的系数;
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #define M(a,b) memset(a,b,sizeof(a))
- using namespace std;
- double A[],B[];
- int n,k1,k2,k3,a,b,c;
- int main()
- {
- int t;
- scanf("%d",&t);
- while(t--)
- {
- M(A,);
- M(B,);
- scanf("%d%d%d%d%d%d%d",&n,&k1,&k2,&k3,&a,&b,&c);
- A[n] = 1.0/(k1*k2*k3);
- B[n] = ;
- for(int i = n-;i>=;i--)
- {
- for(int p = ;p<=k1;p++)
- for(int q = ;q<=k2;q++)
- for(int r = ;r<=k3;r++)
- {
- if(p!=a||q!=b||r!=c)
- {
- A[i] += A[i+p+q+r]/(k1*k2*k3);
- B[i] += B[i+p+q+r]/(k1*k2*k3);
- }
- //cout<<A[i]<<' '<<B[i]<<endl;
- }
- A[i]+=(1.0/(k1*k2*k3));
- B[i]+=;
- //cout<<A[i]<<' '<<B[i]<<endl;
- }
- double ans = B[]/(-A[]);
- printf("%.16f\n",ans);
- }
- return ;
- }
ZOJ Problem Set - 3329(概率DP)的更多相关文章
- LuoguP2523 [HAOI2011]Problem c(概率DP)
傻逼概率\(DP\),熊大坐这,熊二坐这,两熊体积从右往左挤,挤到\(FFF\)没座位了就不合理了 否则就向左歇斯底里爬,每个\(FFF\)编号就组合一下,完闭 #include <iostre ...
- zoj 3329 概率dp
题意:有三个骰子,分别有k1,k2,k3个面.每个面值为1--kn每次掷骰子,如果三个面分别为a,b,c则分数置0,否则加上三个骰子的分数之和.当分数大于n时结束.求游戏的期望步数.初始分数为0 链接 ...
- Code Jam 2008 APAC local onsites Problem C. Millionaire —— 概率DP
题意: 你有X元钱,进行M轮赌博游戏.每一轮可以将所持的任意一部分钱作为赌注(赌注为0元表示这一轮不押),赌注可以是小数的,不是一定要整数.每一轮 赢的概率为P,赢了赌注翻倍,输了赌注就没了.如果你最 ...
- ZOJ 3822 Domination (三维概率DP)
E - Domination Time Limit:8000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu Submi ...
- ZOJ Problem Set - 3329 One Person Game
题目大意:有三个骰子,分别有k1,k2,k3个面. 每次掷骰子,如果三个面分别为a,b,c则分数置0,否则加上三个骰子的分数之和. 当分数大于n时结束.求游戏的期望步数.初始分数为0分析 设 E[i ...
- zoj 3822(概率dp)
ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Ju ...
- ZOJ Problem Set - 3822Domination(DP)
ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...
- BZOJ 2318: Spoj4060 game with probability Problem( 概率dp )
概率dp... http://blog.csdn.net/Vmurder/article/details/46467899 ( from : [辗转山河弋流歌 by 空灰冰魂] ) 这个讲得很好 , ...
- ZOJ Problem Set - 2563 Long Dominoes 【如压力dp】
称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 ...
随机推荐
- Apache服务停止:信号灯超时时间已到,指定的网络名不再可用
环境说明:Apache2.4.10,Windows Server 2008 R2 问题说明: apache服务用于下载文件,但是在运行一段时间后,突然挂了. 其错误提示如下所示: [error] (7 ...
- Intellij IDEA调试功能使用总结
Intellij IDEA调试功能使用总结 这段时间一直在使用Intellij IDEA, 今天把调试区工具的使用方法记录于此. 先编译好要调试的程序. 1.设置断点 选定要设置断点的代码行,在行号的 ...
- [LeetCode] Read N Characters Given Read4 用Read4来读取N个字符
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actua ...
- ECharts学习(4)--仪表盘
1. ECharts中的仪表盘,要使用这个图表时把series中的type属性修改成'gauge',然后在detail中设置仪表盘详情,用于显示数据.最常用的是formatter(格式化函数或者字符串 ...
- 《UNIX环境高级编程》笔记——2.标准和实现
随着UNIX各种衍生版本不断发展壮大,标准化工作就十分必要.其实干啥事都是这样,玩的人多了,必须进行标准化. 一.UNIX标准 1.1 ISO C(ANSI C) ANSI:Amerocan Nato ...
- 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换
经典的异步编程模型(IAsyncResult) 最新的异步编程模型(async 和 await) 将 IAsyncInfo 转换成 Task 将 Task 转换成 IAsyncInfo 示例1.使用经 ...
- WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION
开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...
- 二.Android手机自动化测试真机运行
手机自动化测试用例虽然可以在模拟器上运行,可是模拟器毕竟和真机还是有区别的.在搞定了模拟器上运行测试用例后,我又花了两天的时间,研究了一下真机运行测试用例.期间也遇到了不少问题,不过最终还是搞定了,现 ...
- mongodb安装启动遇到的问题
好不容易下载到了mongodb,配置的时候遇到了不少问题. 下载的是解压包,不是官网的,有一个bin目录,解压到一个自己想要的目录,如d:\mongo,首先把bin复制进来,然后创建data目录,da ...
- Ubuntu学习总结-10 XManager
最近接触到一个很有意思的实验,在这里与大家分享,实验目标在Window显示UBuntu程序. 1 测试环境: Windows8的IP地址 : 192.168.7.126 UBuntu16的IP地址 : ...