1. 程式人生 > >2017 ACM-ICPC 亞洲區(西安賽區)網絡賽: B. Coin 【概率題】

2017 ACM-ICPC 亞洲區(西安賽區)網絡賽: B. Coin 【概率題】

con ont mat -1 bottom using -m desc element

Bob has a not even coin(就是一個不均勻的硬幣,朝上的概率不一定是1/2), every time he tosses the coin, the probability that the coin‘s front face up is q/p(q/p<=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(就是硬幣朝上次數為偶數次的概率和,0次也算).

If the answer is X/Y??, because the answer could be extremely large, you only need to print (X * Y^{-1}) /mod (10^9+7).

Input Format

First line an integer TT, indicates the number of test cases (T100).

Then Each line has 33 integer p,q,k(1<= p,q,k ,k<=10^7) 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

思路:

題目說的有點晦澀。

一個組合數學題。。。。。

 技術分享
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 const int MOD=1e9+7;
 7 typedef long long ll;
 8 ll p,q,k;
 9 
10 ll qmod(ll x,ll n)
11 {
12     ll res=1;
13     while(n){
14         if
(n&1) res=(res*x)%MOD; 15 x=(x*x)%MOD; 16 n/=2; 17 } 18 return res; 19 } 20 21 int main() 22 { 23 int T; 24 cin>>T; 25 while(T--) 26 { 27 cin>>p>>q>>k; 28 ll x=qmod(p,k); 29 ll y=qmod(p-2*q,k); 30 ll ans=((x+y)%MOD*qmod(2*x,MOD-2))%MOD; 31 cout<<ans<<endl; 32 } 33 return 0; 34 }

2017 ACM-ICPC 亞洲區(西安賽區)網絡賽: B. Coin 【概率題】