HDU 4652 Dice(概率dp)
来源:互联网 发布:ce系统导航软件 编辑:程序博客网 时间:2024/05/16 15:08
题目的大意是:dp[i]表示当前在已经投掷出i个不相同/相同这个状态时期望还需要投掷多少次。
求得到连续的相同的期望:是1->m^n的前n项和。这里的解释可以看这里:http://www.matrix67.com/blog/archives/3638
另一种情况:dp[i]=1+(dp[1]+……+dp[i]+(m-i)*dp[i+1])/m
可以迭代系数也可以系数做差:
dp[n]=0
令d[i]=dp[i]-dp[i+1]
则有d[i]=m*dp[i-1]/(m-i),d[0]=1
Dice
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 382 Accepted Submission(s): 248
Special Judge
Problem Description
You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form:
0 m n: ask for the expected number of tosses until the last n times results are all same.
1 m n: ask for the expected number of tosses until the last n consecutive results are pairwise different.
0 m n: ask for the expected number of tosses until the last n times results are all same.
1 m n: ask for the expected number of tosses until the last n consecutive results are pairwise different.
Input
The first line contains a number T.(1≤T≤100) The next T line each line contains a query as we mentioned above. (1≤m,n≤106) For second kind query, we guarantee n≤m. And in order to avoid potential precision issue, we guarantee the result for our query will not exceeding 109 in this problem.
Output
For each query, output the corresponding result. The answer will be considered correct if the absolute or relative error doesn't exceed 10-6.
Sample Input
60 6 10 6 30 6 51 6 21 6 41 6 6101 4534 251 1232 241 3213 151 4343 241 4343 91 65467 1231 43434 1001 34344 91 10001 151 1000000 2000
Sample Output
1.00000000043.0000000001555.0000000002.2000000007.60000000083.20000000025.58631582426.01599003715.17634116024.5410457699.027721917127.908330426103.9754552539.00349551515.0562044724731.706620396
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-9///#define M 1000100#define LL __int64///#define LL long long#define INF 0x7ffffff#define PI 3.1415926535898using namespace std;const int maxn = 1010000;double dp[maxn];int main(){ int T; while(cin >>T) { while(T--) { int u, n, m; cin >>u>>m>>n; if(!u) { printf("%.9lf\n", (pow(m,n)-1.0)/(m*1.0-1.0)); continue; } double sum = 1.0; double d = 1.0; for(int i = 1; i < n; i++) { d = 1.0*m/(m-i)*d; sum += d; } printf("%.9lf\n",sum); } } return 0;}
0 0
- HDU 4652 Dice(概率dp)
- HDU 4652 Dice (概率DP)
- Hdu 4652 Dice 概率DP
- HDU 4652 Dice (概率DP)
- HDU 4652 Dice(概率dp)
- HDU 4652 Dice (概率DP)
- HDU 4599 Dice (概率dp)
- HDU 4599 Dice(概率dp)
- HDU-4599 Dice (概率DP)
- hdu 4652 Dice(dp)
- 概率dp求期望-hdu-4586-Play the Dice
- HDU 4599 Dice 概率DP + 乘法逆元
- HDU 4586Play the Dice 概率dp+等比数列 级数
- Hdu 5955 Guessing the Dice Roll 概率DP+高斯消元
- HDU4599 Dice概率期望DP
- LightOJ1248---Dice (III)(概率dp)
- lightoj - 1064 - Throwing Dice - dp / 概率dp
- hdu 4586 Play the Dice 2013南京邀请赛A 概率dp求期望
- 关于MFC中修改控件字体和背景颜色的方法
- SQLite数据库基础
- 360更新补丁之后,程序无法运行解决历程
- hibernate中cascade属性
- nyoj 90 整数划分 【深搜】
- HDU 4652 Dice(概率dp)
- Objective-C中的Protocol
- UVa 348 最优矩阵链乘 (DP)
- [翻译自mos文章]当job_queue_processes=0 时,cjq 进程依然启动
- IOS编程 之 数据库
- Windows Server 2003下安装PHP +mssql2000
- Java中的数据类型
- 无向连通图求割点(tarjan算法去掉改割点剩下的联通分量数目)
- 深圳云计算公司有哪些