codeforces 108D Basketball Team(简单组合)

本文介绍了一种计算特定条件下篮球队伍组建概率的方法。故事背景设定在一个德国开罗大学的学生和篮球队员 Herr Wafa 身上,他需要计算自己至少有一位来自同一系队友的概率。文章提供了完整的 C 语言代码实现,采用组合数学中的技巧来解决问题。
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).

A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si — how many students who play basketball belong to this department.

Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.

Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.

Input

The first line contains three integers n, m and h (1 ≤ n ≤ 100, 1 ≤ m ≤ 1000, 1 ≤ h ≤ m) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.

The second line contains a single-space-separated list of m integers si (1 ≤ si ≤ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.

Output

Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.

Sample test(s)
input
3 2 1 2 1
output
1.0
input
3 2 1 1 1
output
-1.0
input
3 2 1 2 2
output
0.6666666666666667
Note

In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.

In the second example, there are not enough players.

In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.

 

 

 1 /*
 2 输入:n,m,k,
 3       a[i];
 4 正难则反!总方案数为1-C(s-a[k],n-1)/C(s-1,n-1) 
 5 */
 6 
 7 
 8 #include <stdio.h>
 9 const long long mo = 1000000007;
10 typedef long long ll;
11 
12 int a[2000];
13 int main()
14 {
15     int m, n, k, i, j;
16     while (~scanf("%d%d%d", &n, &m, &k))
17     {
18         int s = 0;
19         for (i = 1; i <= m; i++)
20         {
21             scanf("%d", &a[i]);
22             s += a[i];
23         }
24         if (s < n)
25         {
26             printf("-1.0\n");
27             continue;
28         }
29         double ans, tmp = 1.0;
30         int s1, s2;
31         s1 = s - 1;
32         s2 = s - a[k];
33         for (i = 1; i <= n - 1; i++)
34         {
35             tmp = tmp * s2 / s1;
36             s2--;
37             s1--;
38         }
39         ans = 1.0 - tmp;
40         printf("%.15f\n", ans);
41     }
42 
43     return 0;
44 }
View Code

转载于:https://www.cnblogs.com/skykill/p/3264898.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值