计算客网络赛 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 XY\frac{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)(X∗Y−1)mod(109+7).
Input Format
First line an integer TTT, indicates the number of test cases (T≤100T \le 100T≤100).
Then Each line has 333 integer p,q,k(1≤p,q,k≤107)p,q,k(1\le p,q,k \le 10^7)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
咳咳
当时想到了做法无奈组合数学太垃圾写错了公式最后才发现,要求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的幂数为奇数的项都是负的,二式相加在除以二之后就是答案了,再求一下逆元就是答案。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define LL long long
LL mod=1e9+;
LL inv(LL i) { if(i==)return ;return (mod-mod/i)*inv(mod%i)%mod; }
LL qpow(LL a,LL b){LL r=;for(;b;b>>=,a=a*a%mod)if(b&)r=r*a%mod;return r;}
int main()
{
int T;
LL p,q,k,ans;
cin>>T;
while(T--){ans=;
cin>>p>>q>>k;
ans=qpow(p,k);
ans=(ans+qpow(p-*q,k))%mod;
LL fm=qpow(inv(p),k);
ans=ans*fm%mod;
ans=ans*inv()%mod;
cout<<ans<<endl;
}
return ;
}
计算客网络赛 Coin 二项式定理+逆元的更多相关文章
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 矩阵快速幂
Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face u ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 概率+矩阵快速幂
题目链接: https://nanti.jisuanke.com/t/17115 题意: 询问硬币K次,正面朝上次数为偶数. 思路: dp[i][0] = 下* dp[i-1][0] + 上*dp[i ...
- 计蒜客 17119.Trig Function-切比雪夫多项式+乘法逆元 (2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F)
哈哈哈哈哈哈哈哈哈哈哈哈,终于把这道题补出来了_(:з」∠)_ 来写题解啦. _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ 哈哈哈哈哈哈,从9月16日打了这 ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F. Trig Function(切比雪夫多项式+乘法逆元)
题目链接:哈哈哈哈哈哈 _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ 哈哈哈哈哈哈,从9月16日打了这个题之后就一直在补这道题,今天终于a了,哈哈哈哈哈哈. ...
- 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)
query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...
- 计蒜客 2018南京网络赛 I Skr ( 回文树 )
题目链接 题意 : 给出一个由数字组成的字符串.然后要你找出其所有本质不同的回文子串.然后将这些回文子串转化为整数后相加.问你最后的结果是多少.答案模 1e9+7 分析 : 应该可以算是回文树挺裸的题 ...
- 计蒜客 2019南昌邀请网络赛J Distance on the tree(主席树)题解
题意:给出一棵树,给出每条边的权值,现在给出m个询问,要你每次输出u~v的最短路径中,边权 <= k 的边有几条 思路:当时网络赛的时候没学过主席树,现在补上.先树上建主席树,然后把边权交给子节 ...
- 2018 CCPC网络赛
2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...
- (四面体)CCPC网络赛 HDU5839 Special Tetrahedron
CCPC网络赛 HDU5839 Special Tetrahedron 题意:n个点,选四个出来组成四面体,要符合四面体至少四条边相等,若四条边相等则剩下两条边不相邻,求个数 思路:枚举四面体上一条线 ...
随机推荐
- 读取用户家目录下的配置文件到properties
String conf = System.getProperty("user.home") + File.separator + "a.properties"; ...
- 全面Python小抄(转)
add by zhj: 有些地方不正确,有时间再改吧 原文:Python Cheat Sheet Cheat sheet of Python. Some basic concepts for Pyth ...
- jQuery 查找标签
1 基本选择器 2 基本筛选器 3 属性选择器 4 间接选择 1 基本选择器 //id选择器: $("#id") //标签选择器: $("tagName") / ...
- java.sql.SQLException: The user specified as a definer ('root'@'%') does not exist
权限问题,授权给 root 所有sql 权限 在Navicat for MySQL中按F6进入命令列界面 mysql> grant all privileges on *.* to root@& ...
- numpy利用数组进行数据处理
将条件逻辑表述为数组运算 numpy.where()是一个三目运算的表达式 In [34]: xarr = np.array([1.1,1.2,1.3,1.4,1.5]) In [35]: yarr ...
- centos中搭建nginx环境
原文地址 安装PCRE 源码:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ cd /usr/local/src wget ftp://f ...
- 构建Ruby开发环境(Windows+Eclipse+Aptana Plugin)
1.安装Ruby ①.从http://rubyinstaller.org/downloads/下载安装包:rubyinstaller-2.2.5-x64.exe,直接安装.(so easy) 2.安装 ...
- mysql库安装
如果缺少<mysql/mysql.h> 先安装mysql,然后apt-get install libmysqlclient-dev即可
- JAVA 文件转字节数组转字符串
public static void main(String[] args) throws IOException { byte[] bytes = FileUtils.readFileToByteA ...
- gzframework开发记录
修改窗体权限: 重写方法 修改操作按钮名称 全部自定义增加操作按钮: 插入控件顺序: InsertAfterButton插入到指定控件后面 InsertBeforeButton插入到指定控件前面 公共 ...