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 nm 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
  1. 3 2 1 2 1
output
  1. 1.0
input
  1. 3 2 1 1 1
output
  1. -1.0
input
  1. 3 2 1 2 2
output
  1. 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. #include <stdio.h>
  8. const long long mo = ;
  9. typedef long long ll;
  10.  
  11. int a[];
  12. int main()
  13. {
  14. int m, n, k, i, j;
  15. while (~scanf("%d%d%d", &n, &m, &k))
  16. {
  17. int s = ;
  18. for (i = ; i <= m; i++)
  19. {
  20. scanf("%d", &a[i]);
  21. s += a[i];
  22. }
  23. if (s < n)
  24. {
  25. printf("-1.0\n");
  26. continue;
  27. }
  28. double ans, tmp = 1.0;
  29. int s1, s2;
  30. s1 = s - ;
  31. s2 = s - a[k];
  32. for (i = ; i <= n - ; i++)
  33. {
  34. tmp = tmp * s2 / s1;
  35. s2--;
  36. s1--;
  37. }
  38. ans = 1.0 - tmp;
  39. printf("%.15f\n", ans);
  40. }
  41.  
  42. return ;
  43. }

codeforces 108D Basketball Team(简单组合)的更多相关文章

  1. Codeforces 107B Basketball Team 简单概率

    题目链接:点击打开链接 题意: 给定n m h 表示有m个部门,有个人如今在部门h 以下m个数字表示每一个部门的人数.(包含他自己) 在这些人中随机挑选n个人,问挑出的人中存在和这个人同部门的概率是多 ...

  2. find xargs 简单组合使用

    简单总结下,留作自己以后拾遗...... 一.find xargs 简单组合 ## mv 小结find ./ -type f -name "*.sh"|xargs mv -t /o ...

  3. XKC's basketball team【线段树查询】

    XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...

  4. [单调队列]XKC's basketball team

    XKC's basketball team 题意:给定一个序列,从每一个数后面比它大至少 \(m\) 的数中求出与它之间最大的距离.如果没有则为 \(-1\). 题解:从后向前维护一个递增的队列,从后 ...

  5. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team

    XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...

  6. codeforces 57 C Array(简单排列组合)

    C. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  7. CodeForces - 401C Team(简单构造)

    题意:要求构造一个字符串,要求不能有连续的两个0在一起,也不能有连续的三个1在一起. 分析: 1.假设有4个0,最多能构造的长度为11011011011011,即10个1,因此若m > (n + ...

  8. Codeforces 1108D - Diverse Garland - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...

  9. Codeforces - 702A - Maximum Increase - 简单dp

    DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...

随机推荐

  1. 快速排序和二分查找(Go)

    package main import ( "fmt" "sync") var waitGroup sync.WaitGroup func main() { d ...

  2. Java的LinkedList底层源码分析

    首先我们先说一下,源码里可以看出此类不仅仅用双向链表实现了队列数据结构的功能,还提供了链表数据结构的功能.

  3. Qt数据库之数据库连接池

     前面的章节里,我们使用了下面的函数创建和取得数据库连接: void createConnectionByName(const QString &connectionName) { QSql ...

  4. 将Microsoft SQL Server 2000数据库转换成MySQL数据库

    1. 下载并安装MyODBC.(如果是XP请下载5.3的旧版本,8.x的新版本运行有问题) 2. 创建一个空的MySQL数据库. 3. 在Windows >> 控制面板 >> ...

  5. mysql命令使用3

    算术运算函数 sum()求和 mysql> select sum(price) from books;+------------+| sum(price) |+------------+| 10 ...

  6. 中国MOOC_零基础学Java语言_第7周 函数_2完数

    2 完数(5分) 题目内容: 一个正整数的因子是所有可以整除它的正整数.而一个数如果恰好等于除它本身外的因子之和,这个数就称为完数.例如6=1+2+3(6的因子是1,2,3). 现在,你要写一个程序, ...

  7. 虚拟机三种网络模式及Xshell与Centos7虚拟机连接

    一.虚拟机的三种网络模式 1.桥接模式 a.该模式下的虚拟机可以上外网 b. 局域网之内的主机可以访问该虚拟机(做共享服务器使用) c. 该虚拟机可以和宿主机进行通信 d. 同一台主机相同模式下的虚拟 ...

  8. 应用安全 - 工具 | 数据库 - redis - 漏洞 - 汇总

    未授权访问 Date 类型 未授权访问导致getshell 影响范围 复现 (1)shell反弹 (2)结合SSH服务 (3)结合web服务 分析

  9. [转帖]IDC发布2018下半年中国公有云市场报告

    IDC发布2018下半年中国公有云市场报告:AWS以6.4%的份额名列第四 http://www.itpub.net/2019/05/06/1793/ 电信的公有云 好像是用的 华为的技术. AWS在 ...

  10. 解决org.apache.subversion.javahl.ClientException的方法【】

    重新刷新项目,配置项目,总是报“The project was not built due to "org.apache.subversion.javahl.ClientException” ...