mirror of
https://github.com/Hizenberg469/Algorithms-snippets.git
synced 2026-04-19 22:52:23 +03:00
playground updated
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* cantalan Number using Iterative dp */
|
||||
int catalanNumber( int n ){
|
||||
|
||||
vector<int> dp(n+1);
|
||||
|
||||
dp[0] = dp[1] = 1;
|
||||
|
||||
for(int i = 2 ; i <= n ; i++ ){
|
||||
|
||||
for(int j = 0 ; j <= i ; j++ ){
|
||||
|
||||
dp[i] += dp[j-1]*dp[i-j];
|
||||
}
|
||||
}
|
||||
|
||||
return dp[n];
|
||||
}
|
||||
|
||||
/*
|
||||
Formula for Catalan Number
|
||||
(2n-C-n)/(n+1)
|
||||
*/
|
||||
|
||||
int main(int argc, char* argv[] ){
|
||||
|
||||
cout << catalanNumber(2) << '\n';
|
||||
return 0;
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* cantalan Number using Iterative dp */
|
||||
int catalanNumber( int n ){
|
||||
|
||||
vector<int> dp(n+1);
|
||||
|
||||
dp[0] = dp[1] = 1;
|
||||
|
||||
for(int i = 2 ; i <= n ; i++ ){
|
||||
|
||||
for(int j = 0 ; j <= i ; j++ ){
|
||||
|
||||
dp[i] += dp[j-1]*dp[i-j];
|
||||
}
|
||||
}
|
||||
|
||||
return dp[n];
|
||||
}
|
||||
|
||||
/*
|
||||
Formula for Catalan Number
|
||||
(2n-C-n)/(n+1)
|
||||
*/
|
||||
|
||||
int main(int argc, char* argv[] ){
|
||||
|
||||
cout << catalanNumber(2) << '\n';
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user