• 计算客网络赛 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 }
    
    
    
    
    
  • 相关阅读:
    php xml解析方法
    phpmail 发送邮件失败
    善用Eclipse的代码模板功能
    php5.3 namespace
    MyEclipse6.5配置反编译插件
    程序bug致损失400亿,判程序员坐牢? 搞笑我们是认真的
    ios学习笔记(二)第一个应用程序--Hello World
    ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境
    GJB150-2009军用装备实验室环境试验方法新版标准
    AXI总线简介
  • 原文地址:https://www.cnblogs.com/zzqc/p/7576523.html
Copyright © 2020-2023  润新知