SPOJ Favorite Dice(数学期望)
BuggyD loves to carry his favorite die around. Perhaps you wonder why it's his favorite? Well, his die is magical and can be transformed into an N-sided unbiased die with the push of a button. Now BuggyD wants to learn more about his die, so he raises a question:
What is the expected number of throws of his die while it has N sides so that each number is rolled at least once?
Input
The first line of the input contains an integer t, the number of test cases. t test cases follow.
Each test case consists of a single line containing a single integer N (1 <= N <= 1000) - the number of sides on BuggyD's die.
Output
For each test case, print one line containing the expected number of times BuggyD needs to throw his N-sided die so that each number appears at least once. The expected number must be accurate to 2 decimal digits.
Example
Input:
2
1
12 Output:
1.00
37.24
题意:
甩一个n面的骰子,问每一面都被甩到的次数期望是多少。
思路:
比较简单,公式:初始化dp[]=0; dp[i]=i/n*dp[i]+(n-i)/n*dp[i+1]+1; 化简逆推即可。 求的是dp[0];
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory>
using namespace std;
double dp[];
int main()
{
int T,i,j,n;
scanf("%d",&T);
while(T--){
scanf("%d",&n); dp[n]=;
for(i=n-;i>=;i--) dp[i]=(dp[i+]*(n-i)/n+)*n/(n-i);
printf("%.2lf\n",dp[]);
} return ;
}
SPOJ Favorite Dice(数学期望)的更多相关文章
- SP1026 FAVDICE - Favorite Dice 数学期望
		
题目描述: 一个n面的骰子,求期望掷几次能使得每一面都被掷到. 题解:先谈一下期望DP. 一般地,如果终止状态固定,我们都会选择逆序计算. 很多题目如果顺序计算会出现有分母为 0 的情况,而逆序计算中 ...
 - HDU 4586 Play the Dice(数学期望)
		
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
 - 【HDU4652】Dice(数学期望,动态规划)
		
[HDU4652]Dice(数学期望,动态规划) 题面 Vjudge 有一个\(m\)面骰子 询问,连续出现\(n\)个相同的时候停止的期望 连续出现\(n\)个不同的时候停止的期望 题解 考虑两种分 ...
 - 【整理】简单的数学期望和概率DP
		
数学期望 P=Σ每一种状态*对应的概率. 因为不可能枚举完所有的状态,有时也不可能枚举完,比如抛硬币,有可能一直是正面,etc.在没有接触数学期望时看到数学期望的题可能会觉得很阔怕(因为我高中就是这么 ...
 - [BZOJ 3143][HNOI2013]游走(数学期望)
		
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3143 分析: 易得如果知道了每条边经过的数学期望,那就可以贪心着按每条边的期望的大小赋 ...
 - Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)
		
题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是 ...
 - 数学期望和概率DP题目泛做(为了对应AD的课件)
		
题1: Uva 1636 Headshot 题目大意: 给出一个000111序列,注意实际上是环状的.问是0出现的概率大,还是当前是0,下一个还是0的概率大. 问题比较简单,注意比较大小: A/C & ...
 - [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
		
The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...
 - 【BZOJ2134】单位错选(数学期望,动态规划)
		
[BZOJ2134]单位错选(数学期望,动态规划) 题面 BZOJ 题解 单独考虑相邻的两道题目的概率就好了 没了呀.. #include<iostream> #include<cs ...
 - 【BZOJ1415】【NOI2005】聪聪和可可(动态规划,数学期望)
		
[BZOJ1415][NOI2005]聪聪和可可(动态规划,数学期望) 题面 BZOJ 题解 先预处理出当可可在某个点,聪聪在某个点时 聪聪会往哪里走 然后记忆化搜索一下就好了 #include< ...
 
随机推荐
- [Vue]组件——.sync 修饰符实现对prop 进行“双向绑定”
			
一.同时设置1个 prop 1.以 update:my-prop-name 的模式触发事件,如对于title属性: this.$emit('update:title', newTitle) 2.然后父 ...
 - 《Think in Java》(十三)字符串
			
学完这章后,对 Java 字符串有了重新的认识.自己也看了下 CharSequence,String,StringBuilder,StringBuffer 等类的实现代码.
 - python UI自动化测试
			
为了减小维护成本: 1.UI自动化测试需要有较为稳定的环境 2.代码设计合理,那么我们就需要面向对象的设计一个框架,将重复的代码模块化 一.首先总结一下 UI自动化大概要哪些模块 1.config(配 ...
 - Kotlin Android Studio 环境搭建
			
Kotlin 是一种在 Java 虚拟机上运行的静态类型编程语言,被称之为 Android 世界的Swift,由 JetBrains 设计开发并开源. Kotlin 可以编译成Java字节码,也可以编 ...
 - 使用jenkins自动构建docker容器范例
			
1.登录Jenkins,新建一个自由风格的软件项目. 2.源码管理选择git,并添加Repository URL.Credentials 3.构建选择 Execute Shell,命令如下: dock ...
 - poj-3046-dp
			
Ant Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6829 Accepted: 2514 Desc ...
 - 使用samba初始化开发环境
			
一.系统环境 [root@host-172-20-3-66 samba]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 搞 ...
 - python爬虫之requests模块
			
一. 登录事例 a. 查找汽车之家新闻 标题 链接 图片写入本地 import requests from bs4 import BeautifulSoup import uuid response ...
 - LeetCode OJ:Tenth Line(文件第十行)
			
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
 - LeetCode OJ:Group Anagrams(同字符字符群)
			
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...