Question connection
Question meaning:
Input n, m, representing an n-sided die (the value on the surface is 1-n), throw m times, find the expectation of the maximum value (1?≤?m,?n?≤?105). Analysis:
Assuming that the current maximum value is Max, then the corresponding probability is : sigma (C(m, k) * ((1 / n) ^ k ) * (((Max - 1) / n) ^ (m - k)) ), (1 <= k <= n) ; Simplify to get: sigma (C(m, k) * ((1 / n) ^ k ) * (((Max - 1) / n) ^ (m - k)) ) - ((Max - 1 ) / n) ^ m, (0 <= k <= n); Max ^ m can be obtained from the binomial in the first half, then the simplified result is Max ^ m - (Max - 1) ^ m. Finally, multiply it by Max to get the expectation. Max can use enumeration
After sighing, I found that the efficiency of pow function and fast power are the same. .
int main (){ int n, m; while (~RII(n, m)) { double ans = 0; FE(Max, 1, n) { ans += Max * (pow((double)Max / n, m) - pow((Max - 1.0) / n, m)); } printf("%.10f\n", ans); } return 0;}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn