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的.比較火.链接:这里 ...
随机推荐
- java数组
1.java是否可以像c一次样搞个不定长数组? 不可以那样写,那样写是非法的.数组构造的时候必须指定长度,因为JVM要知道需要在堆上分配多少空间.也就是要初始化数组的话让JVM知道要给数组分配多少空间 ...
- Appium+python的一个简单完整的用例
最近一直在忙,终于有时间来整理一下,传一个简单的用例,运行之后可以看到用例的报告,希望对大家有帮助. HTMLTestRunner这个包网上有很多,大家可以自己下载. 1 import unittes ...
- ssh登录 The authenticity of host 192.168.0.xxx can't be established. 的问题
scp免密码登录:Linux基础 - scp免密码登陆进行远程文件同步 执行scp一直是OK的,某天在本地生成了公钥私钥后,scp到某个IP报以下错误 The authenticity of host ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- FineUI(专业版)v3.0.0 发布,手机、平板和桌面全支持!
FineUI(专业版)v3.0.0 已经正式发布,全面支持手机.平板和桌面! 自 2008 年 4 月发布第一个版本,我们持续更新了 126 个版本,拥有 16000 多位注册用户,130 ...
- markdown语法说明
1.先写一个标题 # 一级标题.相当于 <h1> ## 二级标题.相当于 <h2> ### 三级标题.相当于 <h3> #### 四级标题.相当于 <h4&g ...
- VUE---Missing space before function parentheses
解决方法:
- PowerBuilder笔记
powerbuilder中怎样新建一个pbl文件 在创建pbw之后,右键单击pbw,点新建,弹出对话矿,按图操作,就能创建pbl 主程序入口: 主程序入口代码: // Profile ahzbmysq ...
- 一篇对iOS音频比较完善的文章
转自:http://www.cnblogs.com/iOS-mt/p/4268532.html 感谢作者:梦想通 前言 从事音乐相关的app开发也已经有一段时日了,在这过程中app的播放器几经修改我也 ...
- MapControl图层删除或添加触发监听事件
监听MapControl中对于图层添加和删除的事件 IActiveViewEvents_Event m_MapActiveViewEvents = m_mapControl.Map as IActiv ...