Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is p/q(p/q≤1/2).
The question is, when Bob tosses the coin k times, what's the probability that the frequency of the coin facing up is even number.
If the answer is Y/X, because the answer could be extremely large, you only need to print (X∗Y^(−1))mod(109+7).
Input Format
First line an integer T, indicates the number of test cases (T≤100).
Then Each line has 3 integer p,q,k(1≤p,q,k≤107) indicates the i-th test case.
Output Format
For each test case, print an integer in a single line indicates the answer.
样例输入
2
2 1 1
3 1 2
样例输出
500000004
555555560
组合数学题
附大佬的推导结论:
#include<bits/stdc++.h>
#include <ctime>
using namespace std;
typedef long long ll;
const int MAXN = 1 * 1e5 + 500;
const long long M = 1000000007;
long long quickpow(long long a, long long b)
{
if (b < 0)
{
return 0;
}
long long ret = 1;
a %= M;
for (; b; b >>= 1, a = (a * a) % M)
if (b & 1)
{
ret = (ret * a) % M;
}
return ret;
}
long long inv(long long a)
{
return quickpow(a, M - 2);
}
int main()
{
///clock_t start_time = clock();
///clock_t end_time = clock();
///cout << "Running time is: " << static_cast<double>(end_time - start_time) / CLOCKS_PER_SEC * 1000 << "ms" << endl;
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--)
{
int p, q, k;
cin >> p >> q >> k;
ll ans = 0;
ll Inv = quickpow(p, k);
Inv = inv(Inv);
ll hh = inv(2);
ll a1 = quickpow(p, k);
ll a2 = quickpow(2 * q - p, k);
if (k % 2 == 1)
{
ans = (a1 * Inv % M - a2 * Inv % M + M) % M;
ans = ans * hh % M;
}
else
{
ans = (a1 * Inv + a2 * Inv) % M;
ans = ans * hh % M;
}
cout << ans << endl;
}
return 0;
}

探讨了当一枚不均匀硬币被抛掷k次时,正面朝上次数为偶数的概率计算问题,并提供了一段C++代码实现,用于解决此类问题。
4459

被折叠的 条评论
为什么被折叠?



