期望DP +数学推导

Dice

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 337    Accepted Submission(s): 223
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.
 
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
6
0 6 1
0 6 3
0 6 5
1 6 2
1 6 4
1 6 6
10
1 4534 25
1 1232 24
1 3213 15
1 4343 24
1 4343 9
1 65467 123
1 43434 100
1 34344 9
1 10001 15
1 1000000 2000
 
Sample Output
1.000000000
43.000000000
1555.000000000
2.200000000
7.600000000
83.200000000
25.586315824
26.015990037
15.176341160
24.541045769
9.027721917
127.908330426
103.975455253
9.003495515
15.056204472
4731.706620396
 
Source

题意:一个m个面的筛子。两种询问:(1)平均抛多少次后使得最后n次的面完全一样;(2)平均抛多少次后使得最后n次的面完全不同?

思路:设dp[i]表示i次完全相同、不同时还需要抛的次数期望。

(1)下面首先讨论完全相同的情况。

(2)完全不同的情况:

 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; int main()
{
int t,m,n,s;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d%d%d",&s,&m,&n);
if(s==)
{
printf("%.9lf\n",(.-pow(m,n))/(-m));
}
else if(s==)
{
double sum=.,tmp=.;
for(int i=;i<n;i++)
{
tmp=tmp*m/(m-i);
sum+=tmp;
}
printf("%.9lf\n",sum);
}
}
}
return ;
}

HDOJ 4652 Dice的更多相关文章

  1. 【HDOJ】4652 Dice

    1. 题目描述对于m面的骰子.有两种查询,查询0表示求最后n次摇骰子点数相同的期望:查询1表示最后n次摇骰子点数均不相同的期望. 2. 基本思路由期望DP推导,求得最终表达式.(1) 查询0    不 ...

  2. HDU 4652 Dice(期望)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意:一个m个面的筛子.两种询问:(1)平均抛多少次后使得最后n次的面完全一样:(2)平均抛多少 ...

  3. HDU 4652 Dice:期望dp(成环)【错位相减】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意: 给你一个有m个面的骰子. 两种询问: (1)"0 m n": “最后 ...

  4. HDU 4652 Dice (概率DP)

    版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/36685493 D ...

  5. hdu 4652 Dice 概率DP

    思路: dp[i]表示当前在已经投掷出i个不相同/相同这个状态时期望还需要投掷多少次 对于第一种情况有: dp[0] = 1+dp[1] dp[1] = 1+((m-1)*dp[1]+dp[2])/m ...

  6. HDU 4652 Dice

    嘟嘟嘟 题目大意就是对于一个m面的骰子,回答这么两个问题: 1.求连续扔n次都是同一数字的期望次数. 2.求连续扔n次每一次数字都不相同的期望次数. 对于期望dp特别菜的我来说,这道题已经算是很难了. ...

  7. 概率dp专场

    专题链接 第一题--poj3744 Scout YYF I  链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 ...

  8. Dice (HDU 4652)

    题面: m 面骰子,求1. 出现n个连续相同的停止 ;2. 出现n个连续不同的停止的期望次数.(n, m ≤ 10^6 ) 解析: 当然要先列式子啦. 用f[i](g[i])表示出现i个连续相同(不相 ...

  9. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. Python 数据类型及其用法

    本文总结一下Python中用到的各种数据类型,以及如何使用可以使得我们的代码变得简洁. 基本结构 我们首先要看的是几乎任何语言都具有的数据类型,包括字符串.整型.浮点型以及布尔类型.这些基本数据类型组 ...

  2. 抓鼠标的猫(Win32实现,Codeblocks+GCC编译)

    程序效果: 猫的眼睛一直跟着鼠标移动: 鼠标经过猫的右脚附近时,猫会抓住鼠标.(未使用Hook) 代码: //main.cpp 1 #include <windows.h> #includ ...

  3. Struts2 JQuery UI常用插件

    一.什么是插件 ①是遵循一定接口规范编写的程序 ②是原有系统平台功能的扩展和补充 ③只能运行在规定的系统平台下,而不能单独运行 注:由于jQuery插件是基于jQuery脚本库的扩展,所以所有jQue ...

  4. [No00006D]下载离线版的github for windows【以Github for Windows 3.0.110.为例】

    目录 先上地址后讲原理: 原理: 11个目录的文件怎么一口气下载呢? 最后,把下好的文件批量名,同时将GitHub.exe.manifest也放到软件根目录下(与GitHub.exe同级): 今后的猜 ...

  5. Node webkit启动最大化窗口

    <!DOCTYPE html> <html> <head>     </head> <body>     <p style=" ...

  6. CentOS 7.1, 7.2 下安装dotnet core

    .NET CORE的官方(http://dotnet.github.io/getting-started/)只提供了Windows, Ubuntu14.04, 及Docker(也是基于Ubuntu14 ...

  7. window.open和window.location.href的几种用法

    windows.open("URL","窗口名称","窗口外观设定"); <A href="javascript:windo ...

  8. C/C++实践笔记 008

    逗号运算符优先级最低逗号运算符的值是最后一个的值int a=(1,2);执行结果为2逗号运算符每一条语句都要执行,执行方向从左向右 三目运算符表达式1?表达式2:表达式3 C语言里只有0和非0的区别 ...

  9. __getattitem_ \__setattitem__\__delitem__

    class Foo: def __getitem__(self, item): print('getitem',item) return self.__dict__[item] def __setit ...

  10. linux shell if

    if用法: if [ ] ;then command; elif [ ] ;then command; else command fi if 参数: shell 编程中使用到得if语句内判断参数 –b ...