Codeforces gym 101343 A 数论
来源:互联网 发布:对人工智能的看法 编辑:程序博客网 时间:2024/05/14 00:18
Alaa is on her last day in Singapore, she wants to buy some presents to her family and friends. Alaa knows that the best present in the world will be a chocolate plate for each one of her family members and friends.
Alaa goes to Lucky Plaza shopping mall in Orchard road in order to find all chocolate she needs. Lucky Plaza is a big mall and have many shops that sell chocolate.
On the entrance of Lucky Plaza Alaa wondered if she wants to buy k chocolate plates, what is the probability that she will buy the kthchocolate plate from the nth shop she will visit, knowing that she can visit each shop at most one time. Also she can buy at most one chocolate plate from each shop, and the probability to do that is p. (This probability is the same for all shops in Lucky Plaza)
Alaa wants to finish her mission as soon as possible, so she starts visiting the shops, also she asked you to calculate the answer of her hard question. Can you?
The first line contains three integers m, n, k and real number p (1 ≤ m, n, k ≤ 105) (0 ≤ p ≤ 1), where m is the number of shops that sell chocolate in Lucky Plaza, n is the number of shops Alaa will visit, k is the number of chocolate plates Alaa wants to buy, and p is the probability that Alaa will buy a chocolate plate from any shop that sell chocolate.
The probability p is given with exactly three digits after the decimal point
On a single line print y, where y is the sought probability computed modulo 109 + 7.
The answer y is defined precisely as follows. Represent the probability that Alaa will buy the kth chocolate plate from the nth shop she will visit as an irreducible fraction p / q. The number y then must satisfy the modular equation y × q ≡ p (mod 109 + 7), and be between 0 and 109 + 6, inclusive. It can be shown that under the constraints of this problem such a number y always exists and is uniquely determined.
5 1 1 0.500
500000004
9 4 2 0.800
417600003
100 5 5 0.200
714240005
In the first test case there are 5 shops that sell chocolate in Lucky Plaza, and Alaa wants to buy only 1 chocolate plate. In this case Alaa wants to know what is the probability that she will buy the 1st chocolate plate from the 1st shop she will visit. The probability is 1 / 2, and the answer is 500000004, since (500000004 * 2) % (109 + 7) = 1 % (109 + 7).
In the second test case there are 9 shops that sell chocolate in Lucky Plaza, and Alaa wants to buy only 2 chocolate plates. In this case Alaa wants to know what is the probability that she will buy the 2nd chocolate plate from the 4th shop she will visit. The probability is48 / 625, and the answer is 417600003, since (417600003 * 625) % (109 + 7) = 48 % (109 + 7).
题意:有m个超市 每个超市买到东西的概率为P 且只能买一个东西
问在第n个超市买到第k个东西的概率为多少
假设概率是p/q 那么输出x 使得 x*q=p(mod 1e9+7)
题解:
判掉不可能的情况
答案是 C(m-1,k-1)*p^k*(1-p)^(n-k)
用逆元搞一搞
那么x=p*q^(1e9+5)%(1e9+7)
ps:如果用*1000把p转化为整数 不加eps会wa的很惨
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<math.h>using namespace std;#define scanff(x) scanf("%d",&x)#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)#define drep(i,a,b) for(int i=(int)a;i>=(int)b;i--)long long mod=1000000007;long long inv[100100];int main(){ int m,n,k; inv[1]=1; rep(i,2,100000){ inv[i]=((mod-mod/i)*inv[mod%i])%mod; } double dp; scanf("%d%d%d",&m,&n,&k); if(m<n||k>n){ printf("0\n"); return 0; } scanf("%lf",&dp); long long p=(long long)floor(dp*1000.0+1e-10); long long ans=1; rep(i,1,k-1){ ans=(ans*(n-i))%mod; } rep(i,1,k-1){ ans=(ans*inv[i])%mod; } rep(i,1,k){ ans=(ans*p)%mod; } rep(i,1,n-k){ ans=(ans*(1000-p))%mod; } rep(i,1,n){ ans=(ans*inv[1000])%mod; } printf("%lld\n",ans); return 0;}
- Codeforces gym 101343 A 数论
- Codeforces gym 101353 C 数论
- codeforces gym 100645A
- CodeForces Gym 100803A
- codeforces Gym 101102A
- Codeforces Gym 100372A
- 【Codeforces Gym 100187A】
- Codeforces Gym 100340A Cookies
- codeforces gym 100827A Runes
- Codeforces GYM 100340A Cookies
- Codeforces gym 101350A dp
- Codeforces gym 101102 A dp
- Codeforces Rating Gym-101028A
- Codeforces Gym 100889 A. A Beautiful Array
- CodeForces Gym 100989A LCS (A)
- Codeforces Gym 101158 A. Rearranging a Sequence
- codeforces 484A Bits 数论
- Codeforces 303A 构造+数论
- HNOI2017滚粗记退役记
- 31-TCP 协议(保活定时器)
- Nginx+Tomcat搭建高性能负载均衡集群
- RxJava—过滤操作符
- 老手是这样教新手编程的
- Codeforces gym 101343 A 数论
- AutoEncoder(自动编码器)
- 前端小白学习笔记
- 内网渗透使用代理访问内网
- 微信支付与支付宝的封装
- 程序命名的一些提示
- 设计模式之装饰器模式
- Httpclient post和get请求
- C++ 线程 共享资源保护