From 246dbdbdd5be7821dc0c82304fe69a1dd26833e2 Mon Sep 17 00:00:00 2001 From: ranganeeraj <103856631+ranganeeraj@users.noreply.github.com> Date: Sun, 1 Oct 2023 23:08:13 +0530 Subject: [PATCH] DP Solution for Bell Numbers --- .../Bell Numbers/SolutionByNeeraj.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Dynamic Programming/Bell Numbers/SolutionByNeeraj.cpp diff --git a/Dynamic Programming/Bell Numbers/SolutionByNeeraj.cpp b/Dynamic Programming/Bell Numbers/SolutionByNeeraj.cpp new file mode 100644 index 000000000..d46014925 --- /dev/null +++ b/Dynamic Programming/Bell Numbers/SolutionByNeeraj.cpp @@ -0,0 +1,21 @@ +#include +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; +}