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 mdots. 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.
A single line contains two integers m and n (1 ≤ m, n ≤ 105).
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.
6 1
3.500000000000
6 3
4.958333333333
2 2
1.750000000000
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:
![](https://i-blog.csdnimg.cn/blog_migrate/c139655a313c7b44cdf167d764177120.png)
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
题意:
就是给一个m个面的多面体,求抛n次。得到的最大值得期望;
如果对于最大为K为言。那么最大为k则抛的面数将会有k种情况。而且这k种情况必须有一次在k的面。那么我们假设多面都为k那么抛的概率为(k/m)。总的概率为pow(k/m,n);而这概率中有不满足情况的,就没有第k个面的那个面值,从而减掉。现在就相当于有(k-1)个情况,此时的概率为pow((k-1)/m,n)
所以最后的概率为:pow(k/m,n)- pow((k-1)/m,n)
从而期望就乘以相应的面值就可以了
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64
int main() {
double n,m;
while(cin>>m>>n) {
double a=0 ,b=0;
double ans=0;
for(int i=1; i<=m; i++) {
b=pow((i*1.0)/m,n);
ans+=(b-a)*i;
a=b;
}
printf("%.12f\n",ans);
}
return 0;
}