Crux of the solution is recalling an important mathematical identity:
nCr = (n-1)Cr + (n-1)C(r-1)
//algo
To find nCk; define array a of size n+1;
a[0]=1;
for (int i = 1; i <= n ; i++) {
for (int j = min(i,k); j>= 1; j--) {
a[j] = a[j] + a[j-1];
}
}
return a[k];