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的.比較火.链接:这里 ...
随机推荐
- [转]用Middleware给ASP.NET Core Web API添加自己的授权验证
本文转自:http://www.cnblogs.com/catcher1994/p/6021046.html Web API,是一个能让前后端分离.解放前后端生产力的好东西.不过大部分公司应该都没能做 ...
- Opserver简单部署
版权声明:本文为博主原创文章,未经博主允许不得转载. 一.下载opserver项目 地址:https://github.com/opserver/Opserver/ 二.用vs2012及以上版本打卡o ...
- Django rest_framework 实用技巧
前言: 最近工作中需要用到Django rest_framework框架做API, 边学边写,记录了一些实际工作中需要用到的功能,不是很全也不系统,以后需要什么功能可以在这查询. 后续还会更新其它的用 ...
- c#线程带参数
c#线程带参数 ThreadStart threadStart = delegate { LoadPicture(ds.Tables[0]); }; Thread thread = new Threa ...
- Sqlite3常用的插入方法及性能测试
最近做到的项目涉及一个大数据量缓存重传,其中要用到的sqlite技术,把自己的学习心得整理了一下. SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中. ...
- thusc2016游记&&滚粗记&&酱油记
#include <cstdio> using namespace std; int main(){ puts("转载请注明出处:http://www.cnblogs.com/w ...
- Error Domain=NSURLErrorDomain Code=-999 “The operation couldn’t be completed.
转:http://www.wangzhengdong.com/blog/error-domainnsurlerrordomain-code-999-the-operation-couldnt-be-c ...
- svn1.6在centos6下的使用
版本 CentOS 6:svn 1.6.11 svn1.6版本的不足在于,每个目录递归存在.svn目录:从1.7开始就只有root节点目录存在.svn目录,和git一样了. 但是因为还在用CentOS ...
- 练习:python 操作Mysql 实现登录验证 用户权限管理
python 操作Mysql 实现登录验证 用户权限管理
- adb工具获取appPackage和appActivity
1,手机连接电脑,打开手机调试功能,并运行待测试APP,终端执行: adb shell 2,接着,执行: dumpsys window windows | grep -E 'mFocusedApp' ...