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. js 放回上一页

    window.history.go(-1);//返回上一页不刷新 window.location.href = document.referrer;//返回上一页并刷新

  2. c++11多线程---std::ref和std::cref

    std::ref和std::cref   解释 std::ref 用于包装按引用传递的值. std::cref 用于包装按const引用传递的值.   为什么需要std::ref和std::cref ...

  3. EasyHook Creating a remote file monitor

    In this tutorial we will create a remote file monitor using EasyHook. We will cover how to: 使用EasyHo ...

  4. Android下Native的so编译:使用ndk-build.cmd/.sh

    最近将一个DLL库移植至安卓下,编译出so文件. 经历makefile.cmake等等的入门到放弃..... 最后还是使用android的ndk编译命令来解决 每个NDK文件下,均包含的是所有工具链. ...

  5. Vue模版编译

    一 模版文件 <div> <header> <h1>I'm a template!</h1> </header> <p v-if=&q ...

  6. python3 基本数据类型_1

    不得已,要学习python3了,之前了解到py2与py3有很大不同,不过学起来才能感觉到,比如print. 不过,同样的代码,可以使用py3,py2执行,结果也相似,大家可以看看. 大概因为初学,还未 ...

  7. PHPFPM模式三种运行模式

    1.static模式 static模式始终会保持一个固定数量的子进程,这个数量由pm.max_children定义.   2.dynamic模式 子进程的数量是动态变化的,启动时,会生成固定数量的子进 ...

  8. Java中类和接口

    很形象的接口的使用——针对初学者 里氏代换原则是什么?听起来很高深,不过我们也不是什么学院派,就不讲大道理了,直接拿个例子来说一下. 我们拿人和程序员举个例子.人是一个大类,程序员是继承自人的子类.看 ...

  9. ELK7.4.0分析nginx json日志

    ELK7.4.0单节点部署 环境准备 安装系统,数据盘设置为/srv 内核优化参考 我们需要创建elk专用的账号,并创建所需要的目录并授权 useradd elk; mkdir /srv/{app,d ...

  10. dubbo中拦截生产者或消费者服务方法调用

    比如当前有个需求,需要拦截dubbo的服务提供方或者服务消费方的方法,判断参数中是否包含某个关键字进行拦截阻止执行,那么我们可以通过使用dubbo的SPI机制通过实现Filter类来拦截,话不多说直接 ...