博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SPOJ1026 概率DP
阅读量:7069 次
发布时间:2019-06-28

本文共 1357 字,大约阅读时间需要 4 分钟。

 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:2112Output:1.0037.24

 

题意:

甩一个n面的骰子,问每一面都被甩到的次数期望是多少。

思路:

dp[i]:抛到i面的期望次数,dp[i]=dp[i-1]+n/(n-i+1)

代码:

1 #include"bits/stdc++.h" 2  3 #define db double 4 #define ll long long 5 #define vl vector
6 #define ci(x) scanf("%d",&x) 7 #define cd(x) scanf("%lf",&x) 8 #define cl(x) scanf("%lld",&x) 9 #define pi(x) printf("%d\n",x)10 #define pd(x) printf("%f\n",x)11 #define pl(x) printf("%lld\n",x)12 #define rep(i, n) for(int i=0;i

 

 

转载于:https://www.cnblogs.com/mj-liylho/p/9535931.html

你可能感兴趣的文章
怎么调试React,使用Chrome引入的source-map文件
查看>>
opengl 关键函数解析
查看>>
ngx_lua常用变量参数
查看>>
替换文件夹中特定字符串工具类
查看>>
chrome使用百度搜索卡死 解决办法
查看>>
linux开机自启动命令
查看>>
TabBar with Expands
查看>>
使用GCD的dispatch_once创建单例
查看>>
jpa中的一对多级联删除
查看>>
面试需要的基础知识-二维数组中的查找
查看>>
开源 java CMS - FreeCMS2.8 数据对象 dictionaryClass
查看>>
Android应用安全开发之浅谈加密算法的坑
查看>>
MySQL ERROR 1071 (42000): Specified key was too...
查看>>
OPENCART模板 5 折
查看>>
OptionsMenu 详解
查看>>
linux 下 apache 单独安装独立模块
查看>>
从发明新的排序算法开始扯淡(四,挑战)
查看>>
JAVA学习笔记—JDK1.5的自动装箱与拆箱
查看>>
mini-springframework-简化版Spring实现设计
查看>>
快速开发基于 HTML5 网络拓扑图应用
查看>>