Question link: Click the open link
Question:
Given N M H
Indicates that there are m departments, and an individual is in the department H
The following M numbers indicate the number of people in each department. (Including himself)
N people are randomly selected among these people, and the probability of a person in the same department as this person is asked.
This person must be among the N people picked out.
Reverse Thinking. The answer is 1-impossible probability.
Impossible probability = C (n-1, sum-1-a [H])/C (n-1, Sum-1)
The denominator of the two combinations is the same, so you only need to divide the molecular parts of the two combinations.
#include <cstdio>#include <iostream>#include <algorithm>#include <string.h>#include <map>#include <set>using namespace std;#define N 10010int n, m, h, a[N];void solve(){ int sum = 0; for(int i = 1; i <= m; i++) scanf("%d",&a[i]), sum += a[i]; if(sum < n){ puts("-1");return ; } n--; sum--; a[h]--; if(sum - a[h] < n){puts("1");return;} double ans = 1.0; double x = sum-a[h], y = sum; for(int i = 1; i <= n; i++) { ans *= x / y; x--; y--; } printf("%.10f\n", 1.0 - ans);}int main(){ while(~scanf("%d %d %d",&n,&m,&h)){ solve(); } return 0;}
Codeforces sort B basketball team simple probability