嘴巴题9 Codeforces 453A. Little Pony and Expected Maximum
A. Little Pony and Expected Maximum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains m dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.
Input
A single line contains two integers m and n (1 ≤ m, n ≤ 105).
Output
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4.
Examples
Input
6 1
Output
3.500000000000
Input
6 3
Output
4.958333333333
Input
2 2
Output
1.750000000000
Note
Consider the third test example. If you've made two tosses:
You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
题目大意
给你一个\(m\)个面的骰子,第\(i\)个面上的数为\(i\),投\(n\)次,问这\(n\)次中最大值的期望。
题解
考虑枚举最大值\(i\),直接算不太好算,考虑容斥。
最大值为\(i\)的方案 = 所有数小于等于\(i\)的方案 - 不包含\(i\)的方案,即为所有数小于等于\(i\)且包含\(i\)的方案,即
\]
总方案数除以\(m^n\)即可
由于太大可能会溢出,要边计算边除,即
\]
答案即为$$\sum_{i=1}^{m} Ans_i$$
嘴巴题9 Codeforces 453A. Little Pony and Expected Maximum的更多相关文章
- CodeForces - 453A Little Pony and Expected Maximum
http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= ...
- CodeForces 454C Little Pony and Expected Maximum
Little Pony and Expected Maximum Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I6 ...
- codeforces C. Little Pony and Expected Maximum
题意:一个筛子有m个面,然后扔n次,求最大值的期望; 思路:最大值为1 有1种,2有2n-1种, 3有3n -2n 种 所以为m的时有mn -(m-1)n 种,所以分别求每一种的概率,然后乘以这 ...
- cf 453A.Little Pony and Expected Maximum
水了一上午.. 拿6面举例子吧,因为是投掷m次取最大,最大是1概率(1/6)^m;最大是2就可以取到(1,2)那么概率就是(1/3)^m-(1/6)^m.(当前减去上一个) #include<b ...
- Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题
A. Little Pony and Expected Maximum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...
- 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)的是 ...
- 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)
A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...
- E. Little Pony and Expected Maximum(组合期望)
题目描述: Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megaby ...
- CF453A Little Pony and Expected Maximum 期望dp
LINK:Little Pony and Expected Maximum 容易设出状态f[i][j]表示前i次最大值为j的概率. 转移很显然 不过复杂度很高. 考虑优化.考虑直接求出最大值为j的概率 ...
随机推荐
- Socket心跳包异常检测的C语言实现,服务器与客户端代码案例
在Socket心跳机制中,心跳包可以由服务器发送给客户端,也可以由客户端发送给服务器,不过比较起来,前者开销可能较大.本文实现的是由客户端给服务器发送心跳包,服务器不必返回应答包,而是通过判断客户在线 ...
- upper_bound() lower_bound() 用法
头文件 #include<algorithm> #include<iostream>#include<vector>#include<algorithm> ...
- Centos6.5离线安装gcc
木有网的centos折腾起来简直费劲的不要不要的~ 学校的虚拟机最开始只安装了一个libgcc-4.4.7-4,然而这是不够用的,比如安装软件的时候,需要输入"./configure&quo ...
- vc枚举本机端口信息
关于查看本机端口信息,可能大多数人都知道在cmd下的netstat 命令,殊不知该命令在底层也是调用相关api来实现的,相关函数有:GetTcpTableGetExtendedTcpTableGetU ...
- ubuntu切换到root用户
我们都知道使用su root命令,去切换到root权限,此时会提示输入密码,可是怎么也输不对,提示"Authentication failure", 解决办法如下 su root ...
- PHP算法之两数相加
给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和 ...
- sql server 的存储过程
存储过程说白了就是一堆 SQL 的合并.中间加了点逻辑控制. 存储过程运行流程 创建不带参数存储过程 --创建存储过程 if (exists (select * from sys.objects wh ...
- java运行字符串代码
本文链接:https://blog.csdn.net/junlong750/article/details/50945883
- [转]Nginx配置详解
Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. Nginx功能丰富,可作为HTTP服务器,也可作为 ...
- C/C++ 公有函数无法返回私有的类对象解决方案
{ 能出这种错的说明还需要提升C++,增强对类的理解 解决方案:把你的私有的对象的私有的拷贝构造或者同类赋值改为公开的 }