zoukankan      html  css  js  c++  java
  • 计算客网络赛 Coin 二项式定理+逆元

    https://nanti.jisuanke.com/t/17115

    Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is qp(qp≤12)frac{q}{p}(frac{q}{p} le frac{1}{2})pq​​(pq​​21​​).

    The question is, when Bob tosses the coin kkk times, what's the probability that the frequency of the coin facing up is even number.

    If the answer is XYfrac{X}{Y}YX​​, because the answer could be extremely large, you only need to print (X∗Y−1)mod(109+7)(X * Y^{-1}) mod (10^9+7)(XY1​​)mod(109​​+7).

    Input Format

    First line an integer TTT, indicates the number of test cases (T≤100T le 100T100).

    Then Each line has 333 integer p,q,k(1≤p,q,k≤107)p,q,k(1le p,q,k le 10^7)p,q,k(1p,q,k107​​) 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
    咳咳
    当时想到了做法无奈组合数学太垃圾写错了公式最后才发现,要求k次抛中有偶数次正面向上的概率,设每一次向上概率为P,显然答案是SUM{C(k,x)*Px*(1-P)k-x},当时把二项式系数给扔了卧槽。
    要求x必须是偶数只要xjb构造一个就好了,令S1=(P+(1-P))k , S2=((-P)+(1-P))k 显然S2中P的幂数为奇数的项都是负的,二式相加在除以二之后就是答案了,再求一下逆元就是答案。
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 using namespace std;
     6 #define LL long long
     7 LL mod=1e9+7;
     8 LL inv(LL i) {  if(i==1)return 1;return (mod-mod/i)*inv(mod%i)%mod; }
     9 LL qpow(LL a,LL b){LL r=1;for(;b;b>>=1,a=a*a%mod)if(b&1)r=r*a%mod;return r;}
    10 int main()
    11 {
    12     int T;
    13     LL p,q,k,ans;
    14     cin>>T;
    15     while(T--){ans=0;
    16         cin>>p>>q>>k;
    17         ans=qpow(p,k);
    18         ans=(ans+qpow(p-2*q,k))%mod;
    19         LL fm=qpow(inv(p),k);
    20         ans=ans*fm%mod;
    21         ans=ans*inv(2)%mod;
    22         cout<<ans<<endl;
    23     }
    24     return 0;
    25 }
    
    
    
    
    
  • 相关阅读:
    Linux下汇编语言学习笔记31 ---
    Linux下汇编语言学习笔记30 ---
    Linux下汇编语言学习笔记27 ---
    Linux下汇编语言学习笔记26 ---
    Linux下汇编语言学习笔记25 ---
    设计模式 关注点分离
    设计模式 关注点分离
    ALAsset和ALAssetRepresentation详解
    ALAsset和ALAssetRepresentation详解
    VIEW当中自定义属性的使用
  • 原文地址:https://www.cnblogs.com/zzqc/p/7576523.html
Copyright © 2011-2022 走看看