-
-
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.
Merge pull request #1923 from ranganeeraj/patch-11
DP Solution for Bell Numbers
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
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,21 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int bellNumber(int n) { | ||
int bell[n+1][n+1]; | ||
bell[0][0] = 1; | ||
for (int i=1; i<=n; i++) { | ||
bell[i][0] = bell[i-1][i-1]; | ||
for (int j=1; j<=i; j++) | ||
bell[i][j] = bell[i-1][j-1] + bell[i][j-1]; | ||
} | ||
return bell[n][0]; | ||
} | ||
int main () { | ||
cout << "\nEnter Number\t:\t"; | ||
unsigned int number; | ||
cin >> number; | ||
cout <<"\nThe result is\t:\t" << bellNumber(number); | ||
cout << endl; | ||
return 0; | ||
} |