Skip to content

Commit 53df2de

Browse files
authored
Merge pull request #1916 from rayeenshoaib/patch-34
Bell numbers using DP
2 parents cd0855e + e87f305 commit 53df2de

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int bellNumber(int n) {
5+
int bell[n+1][n+1];
6+
bell[0][0] = 1;
7+
for (int i=1; i<=n; i++) {
8+
bell[i][0] = bell[i-1][i-1];
9+
for (int j=1; j<=i; j++)
10+
bell[i][j] = bell[i-1][j-1] + bell[i][j-1];
11+
}
12+
return bell[n][0];
13+
}
14+
int main () {
15+
cout << "\nEnter Number\t:\t";
16+
unsigned int number;
17+
cin >> number;
18+
cout <<"\nThe result is\t:\t" << bellNumber(number);
19+
cout << endl;
20+
return 0;
21+
}

0 commit comments

Comments
 (0)