题解:
火焰飞弹击中碎片的概率
那么未击中的概率
若要摧毁碎片,那么至少需要 h / a 向上取整次
根据二项分布的知识,最后答案为
因为要取模运算,为了优化时间复杂度,我们先将阶乘和阶乘逆元预处理出来
阶乘求逆元:
逆元可以看作是求倒数,那么就有
因此可以先求出第n项的阶乘逆元然后倒着推出前n-1项的阶乘逆元
代码如下:
//#include <unordered_map>
//#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) (-x & x)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
const int mod = 1e9 + 7;
const int N = 5e6 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
LL n, r1, r2, r, a, h;
LL f[N], rf[N];
inline LL ksm(LL a, int p)//快速幂
{
a = a % mod;
LL res = 1;
while(p)
{
if(p&1) res = res * a % mod;
a = a * a % mod;
p >>= 1;
}
return res;
}
inline LL C(int a,int b)
{
return f[a] * rf[b] % mod * rf[a-b] % mod;
}
inline void init()
{
f[0] = 1;
for(int i=1; i<=n; i++) //预处理出阶乘
f[i] = f[i-1] * i % mod;
rf[n] = ksm(f[n], mod - 2);
for (int i = n - 1; i >= 0; i -- )//阶乘逆元
rf[i] = rf[i + 1] * (i + 1) % mod;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
IOS;
cin >> n >> r1 >> r2 >> r >> a >> h;
init();
int k = (h - 1) / a + 1;
if (k > n)
{
cout << "0";
return 0;
}
if (r1 + r >= r2)
{
cout << "1";
return 0;
}
LL rr2 = ksm(r2 * r2, mod - 2);
LL p = (r1 + r) * (r1 + r) % mod * rr2 % mod;//概率p
LL q = (r2 * r2 % mod - (r1 + r) * (r1 + r) % mod + mod) % mod * rr2 % mod;//概率q
LL pp = ksm(p, k), qq = ksm(q, n - k);
LL ans = 0;
for (int i = k; i <= n; i ++ )
{
ans = (ans + C(n, i) * pp % mod * qq % mod) % mod;
pp = pp * p % mod;
qq = qq * ksm(q, mod - 2) % mod;
}
cout << ans;
return 0;
}