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
题意:给出总人数,和总的背包数,以及朋友数目,求每一个朋友都能被分到一个背包的概率。
直接做显然不行,然后就推公式啦。左边是朋友都有书包的概率。
代码:
#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;
}