Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. /*
  2. ID: keyvank2
  3. TASK: combo
  4. LANG: C++
  5. */
  6.  
  7. #include <bits/stdc++.h>
  8.  
  9. #define ff first
  10. #define ss second
  11. #define pb push_back
  12. #define mp make_pair
  13. #define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
  14. #define FORV(i, v) FOR(i, 0, ((v).size()))
  15. #define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
  16. #define setmax(i) const int maxn = (int) i;
  17. #define setmod(i) const int MOD = (int) i;
  18. #define all(a) a.begin(),a.end()
  19. #define autodef(x,v) typeof(v) x = (v)
  20. #define autoref(x,v) typeof(v)& x = (v)
  21. #define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)
  22.  
  23. //typedef complex<double> Point;
  24. //#define X real()
  25. //#define Y imag()
  26.  
  27. using namespace std;
  28.  
  29. //ifstream fin("");
  30. //ofstream fout("");
  31. //#define cin fin
  32. //#define cout fout
  33.  
  34. typedef long long ll;
  35. typedef long double ld;
  36. typedef vector<int> vi;
  37. typedef pair<int,int> pii;
  38. typedef pair<ll,ll> pll;
  39. typedef pair<ld,ld> pdd;
  40. typedef pair<pii,int> ppi;
  41. typedef pair<pll,ll> ppl;
  42. typedef pair<int,pii> pip;
  43. typedef pair<ll,pll> plp;
  44. typedef pair<pii,pii> ppp;
  45.  
  46. const int INF = (int) 2e9;
  47. const ll INFL = (ll) 9e18;
  48. const int MAXINT = ((~0) ^ (1 << 31));
  49. const ll MAXLL = ((~0) ^ ((ll)1 << 63));
  50.  
  51. template<class T> inline T pow2(T a) { return a*a;}
  52. template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
  53. template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}
  54.  
  55. //srand (time(NULL));
  56.  
  57. bool debug = 1;
  58.  
  59. setmod(1e9+7);
  60. setmax(2e5+10);
  61.  
  62. ll fact[maxn], rfact[maxn];
  63.  
  64. ll powmod(ll a, ll b)
  65. {
  66. if(!b)
  67. return 1;
  68. ll t = powmod(a,b/2);
  69. t = (t*t)%MOD;
  70. if(b&1)
  71. t = (t*a)%MOD;
  72. return t;
  73. }
  74.  
  75. void pre()
  76. {
  77. fact[0] = 1;
  78. FOR(i,1,maxn)
  79. fact[i] = (fact[i-1]*i)%MOD;
  80. FOR(i,0,maxn)
  81. rfact[i] = powmod(fact[i],MOD-2);
  82.  
  83. if(debug)
  84. {
  85. FOR(i,0,20)
  86. cout << fact[i] << " ";
  87. cout << endl;
  88. FOR(i,0,20)
  89. cout << rfact[i] << " ";
  90. cout << endl;
  91. }
  92. }
  93.  
  94. ll catalan(ll n)
  95. {
  96. return (fact[2*n]*rfact[n])%MOD *rfact[n] %MOD *powmod(n+1,MOD-2)%MOD;
  97. }
  98.  
  99. ll catalan2(ll n)
  100. {
  101. if(n == 0)
  102. return 1;
  103. ll ans = 0;
  104. FOR(i,0,n)
  105. ans += catalan2(i)*catalan2(n-1-i);
  106. return ans;
  107.  
  108. }
  109.  
  110. int main()
  111. {
  112. ios_base::sync_with_stdio(0);cin.tie(0);
  113.  
  114. pre();
  115. int t;
  116. cin >> t;
  117. FOR(i,0,t)
  118. {
  119. int n;
  120. cin >> n;
  121. cout << catalan(n) << endl;
  122. if(debug)
  123. {
  124. cout << "validator : " << catalan2(n) << endl;
  125. assert(catalan(n) == catalan2(n));
  126. }
  127. }
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement