3985. I guess the gift is a bag!

Boss Yu said that he will give gifts to the members who passed this TJU ACM recruitment contest and I guess the gifts will be some bags.
But here comes the problem: suppose there are N people and M bags. I have K good friends among the N people. Now I want to know what’s the possibility of each of the K people can have a bag.
Can you tell me the possibility?
Input

The first line contains a single integer T represents the number of test cases, for each test case there are only three integers N, M and K(1≤K≤M≤N≤1000,T≤100000).
Output

The possibility of each of the K people can have a bag, rounded to four decimal places.
Sample Input

3
2 1 1
21 3 2
1000 500 2
Sample Output

0.5000
0.0143
0.2497

题意:给出总人数,和总的背包数,以及朋友数目,求每一个朋友都能被分到一个背包的概率。

直接做显然不行,然后就推公式啦。左边是朋友都有书包的概率。

CmknkCmn=ansni+1i

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
double c(int n,int k)
{
    double ans=1;
    for(int i=1;i<=k;i++)
    {
        ans*=n-i+1;
        ans/=i;
    }
    return ans; 
}

int main (void)
{
    int t;
    cin>>t;
    while(t--)
    {
        int m,n,k;
        scanf("%d %d %d",&n,&m,&k);
        printf("%.4f\n",c(n-k,m-k)/c(n,m));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值