The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct. ― Donald E. Knuth

# Algorithms

## Dynamic Programming

Problem :-
Evaluate nCr i.e combination ( n, r ).
Combination refer to the combination of n things taken r at a time without repetition.
Mathematically, nCr = n! / r! * ( n - r )!

Solution :-
Let C ( n , r ) denotes combination of n things taken r at a time.
As per recursive formulation, C ( n , r ) = C ( n - 1 , r - 1 ) + C ( n - 1 , r ) with C ( n , 0 ) = C ( n , n ) = 1.
This is basically the structure of an optimal solution defined recursively.
We can maintain a 2D array C [ n + 1 ][ r + 1 ] which stores all the combination values starting from C ( 0 , 0 ). Finally, C [ n ][ r ] gives the value of C ( n , r ).
See the program below for the solution.