Skip to content

Commit b2c8b1a

Browse files
authored
Merge pull request #683 from rudradesai200/master
adding catalanNumbers.cpp
2 parents 046f52d + ed811e8 commit b2c8b1a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

C++/catalanNumbers.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
#include<assert.h>
3+
using namespace std;
4+
5+
unsigned long int catalanDP(unsigned int n)
6+
{
7+
unsigned long int catalan[n+1];
8+
9+
catalan[0] = catalan[1] = 1;
10+
for (int i=2; i<=n; i++)
11+
{
12+
catalan[i] = 0;
13+
for (int j=0; j<i; j++)
14+
catalan[i] += catalan[j] * catalan[i-j-1];
15+
}
16+
return catalan[n];
17+
}
18+
19+
int main(){
20+
assert(catalanDP(9) == 4862);
21+
}

0 commit comments

Comments
 (0)