Advertisement
math2do

nth_catalan

May 2nd, 2020
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. /**
  2.  *    author:  Mathura Tudu
  3.  *    created: 25.04.2020 14:06:08 IST
  4. **/
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. using namespace std;
  9.  
  10. using ull = unsigned long long int;
  11. const int N = 100;
  12. vector <ull> catalan(N + 1);
  13.  
  14. int main() {
  15.   auto calc = [&] () {
  16.     catalan[0] = catalan[1] = 1;
  17.     for (int i = 2; i <= N; i++) {
  18.       catalan[i] = 0;
  19.       for (int j = 0; j < i; j++) {
  20.         catalan[i] += catalan[j] * catalan[i - j - 1];
  21.       }
  22.     }
  23.   };
  24.   calc();
  25.   //catalan[n - 2] gives the answer for n-sided polygon
  26.   for (int n = 3; n <= 10; n++) {
  27.     cout << catalan[n - 2] << endl;
  28.   }
  29.   return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement