Skip to content

Commit ddf7899

Browse files
committed
Fixes #222
1 parent 45ea049 commit ddf7899

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Dynamic Programming/binomial_coefficient.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Write a function that takes two parameters n and k and returns the value of Binomial Coefficient C(n, k).
2+
// For example, our function should return 6 for n = 4 and k = 2, and it should return 10 for n = 5 and k = 2.
3+
4+
// The idea we have used here is inspired by the pascal triangle.
5+
/*
6+
1
7+
1 1
8+
1 2 2 1
9+
1 3 4 3 1 */
10+
111
#include <bits/stdc++.h>
212
using namespace std;
313

@@ -13,7 +23,7 @@ int binomial(int n, int r)
1323
{
1424
for (int j = 1; j <= r; j++)
1525
{
16-
if (i == j || j == 0)
26+
if (i == j || j == 0) // Base Condition
1727
dp[i][j] = 1;
1828
else
1929
{ // we have taken a mod, so that higher results can be calculted too.

0 commit comments

Comments
 (0)