You are on page 1of 2

S2 BTech

C Programming
Code-Chef Submission

Name: ANANDHA KRISHNAN. R


Roll No: AM.EN.U4ECE17109

QUESTION: 2: FTRIP
EASY
Alice's school is planning to take some students from her class on a
field trip. Alice is really excited about it. There are a total of S
students in her class. But due to budget constraints, the school is
planning to take only N students for the trip. These students will be
picked randomly. And each student has equal chance of being
picked.

Alice's friend circle has M students including her. Though she is


excited about the field trip, she will enjoy it only if there are atleast K
of her friends with her on the trip. She is wondering what are the
chances of that happening. She needs your help. Tell her the
probability that she will enjoy given that she goes on the trip.
//ANANDHA KRISHNAN.R
#include <stdio.h>
#define MAX(a,b) (a>b)? (a):(b)

int main()
{int T,S,N,M,K,t,i;
double tmp,fav,tot;
scanf("%d",&T);
for(t=1;t<=T;t++)
{scanf("%d%d%d%d",&S,&N,&M,&K);
S--;
N--;
M--;
tmp=1,fav=0,tot=1;
i=MAX(N-S+M,0);
if(i>=K)fav = 1;
for(;i<M && i<N;i++){
tmp *= (double)(M-i)*(N-i)/((S-M-N+i+1)*(i+1));

if(i+1>=K) fav += tmp;


tot += tmp;
}
printf("%.6lf\n",fav/tot);
}
return 0;
}

APPROACH:

You might also like