数学期望抛硬币
发布时间
阅读量:
阅读量
\mathrm{Problem}

\mathrm{Solution}
设 f_i 用于表示当存在 i 枚硬币时,所对应的期望步数,此时可得公式:f_i={p(f_{i-1}+1)+(1-p)(f_{i-1}+f_i+1)}
由此可推导出:f_i=\prod_{i=1}^{k} 1/p^k
\mathrm{Code}
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int P = 998244353;
int power(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1) res = res * a % P;
a = a * a % P, b >>= 1;
}
return res;
}
全部评论 (0)
还没有任何评论哟~
