我是靠谱客的博主 温柔大象,这篇文章主要介绍2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin(组合数),现在分享给大家,希望可以做个参考。

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

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

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

Input Format

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

Then Each line has 33 integer 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.

样例输入

复制代码
1
2
3
2 2 1 1 3 1 2

样例输出

复制代码
1
2
500000004 555555560

这题的答案公式很好推,但是怎么化简不好构造;利用了组合数中的二项式展开技巧,因为正面朝上的次数为偶数 所以需要把奇数项消除 构造二项式 令第二项为负数即可消除

思路:




复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL mod = 1e9+7; LL quick(LL x, LL n) { LL r=1; while(n) { if(n&1) r=r*x%mod; n>>=1; x=x*x%mod; } return r%mod; } int main() { //cout<<quick(2,mod-2)<<endl; int t; scanf("%d", &t); while(t--) { LL p, q, k; scanf("%lld %lld %lld", &p, &q, &k); LL x=quick(p-2*q,k)*quick(quick(p,k)%mod,mod-2)%mod; x=(x+1)*quick(2,mod-2)%mod; printf("%lldn",x); } return 0; }

最后

以上就是温柔大象最近收集整理的关于2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin(组合数)的全部内容,更多相关2017内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部