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
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.

 /*
输入:n,m,k,
a[i];
正难则反!总方案数为1-C(s-a[k],n-1)/C(s-1,n-1)
*/ #include <stdio.h>
const long long mo = ;
typedef long long ll; int a[];
int main()
{
int m, n, k, i, j;
while (~scanf("%d%d%d", &n, &m, &k))
{
int s = ;
for (i = ; i <= m; i++)
{
scanf("%d", &a[i]);
s += a[i];
}
if (s < n)
{
printf("-1.0\n");
continue;
}
double ans, tmp = 1.0;
int s1, s2;
s1 = s - ;
s2 = s - a[k];
for (i = ; i <= n - ; i++)
{
tmp = tmp * s2 / s1;
s2--;
s1--;
}
ans = 1.0 - tmp;
printf("%.15f\n", ans);
} return ;
}

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. saml2协议sp-initial登录过程

    登录过程如下所示: 一次完整的saml认证过程,包括一次samlrequest和samlresponse, 首先用户如果想访问一个sp,sp会先检验用户是否登录,如果用户已经登录,即可以正常访问sp的 ...

  2. 【1】mongoDB 的安装及启动

    MongoDB是一个面向文档(document-oriented)的数据库,不是关系型数据库.与关系型数据库相比,面向文档的数据库没有"行"的概念,取而代之的是"文档&q ...

  3. Mysql的caching_sha2_password的坑

    概述 今天我用homebrew安装Mysql8.0,安装完成之后,用Workbench和Sequel Pro连接数据库都失败了,并且都报caching_sha2_password相关的错误,经过查资料 ...

  4. Openstack_单元测试

    目录 目录 单元测试的原理 单元测试的实现 最后 单元测试的原理 单元测试中的单元可以是一个模块文件, 测试的内容就是模块自身的代码(非导入型代码)是否正确执行. 其中包含了测试代码的正反向逻辑是否正 ...

  5. Vue中的model

    v-model语法糖: model: 默认情况下,一个组件上的 v-model 会把 value 用作 prop 且把 input 用作 event, 但是一些输入类型比如单选框和复选框按钮可能想使用 ...

  6. 阶段3 1.Mybatis_04.自定义Mybatis框架基于注解开发_2 回顾自定义mybatis的流程分析

  7. flask及扩展源码解读

    先放几篇文章 http://www.jianshu.com/p/adbea1783e2b http://blog.csdn.net/github_39605023/article/details/76 ...

  8. 【ABAP系列】SAP 系统的消息类型分析 MESSAGE TYPE

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 系统的消息类型分析 ME ...

  9. finereport点击图表钻取到明细表包括参数传递

    1.  点击编辑图表 2.  参数传递 3.  选择分类名称 4.  钻取明细表获取 inputs 值得方法 使用公司 $inputs   获取钻取传来的值

  10. eclipse maven 项目突然所有的JS方法都失效了

    原因:JS 或者 jQuery 有严重的语法错误