-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DP Solution for Binomial Coefficient
- Loading branch information
1 parent
cabb853
commit 6273440
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
Dynamic Programming/Binomial Coefficient/SolutionByNeeraj.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int binomialCoeff(int n, int k) { | ||
int C[k+1]; | ||
memset(C, 0, sizeof(C)); | ||
|
||
C[0] = 1; | ||
|
||
for (int i = 1; i <= n; i++) { | ||
for (int j = min(i, k); j > 0; j--) | ||
C[j] = C[j] + C[j-1]; | ||
} | ||
return C[k]; | ||
} | ||
|
||
int main () { | ||
cout << "\nEnter n\t:\t"; | ||
int number; | ||
cin >> number; | ||
cout << "\nEnter k\t:\t"; | ||
int k; | ||
cin >> k; | ||
cout <<"\nThe result is\t:\t" << binomialCoeff(number, k); | ||
cout << endl; | ||
return 0; | ||
} |