题意
在棋盘上行走,不能越过对角线
思路
递推式
h(0)=1,h(1)=1
h(n)= h(0)*h(n-1)+h(1)*h(n-2) + … + h(n-1)h(0) (n>=2)
h(n)=h(n-1)*(4*n-2)/(n+1);
h(n)=C(2n,n)/(n+1);
1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, …
代码
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x7f7f7f7f;
const int maxn = 35;
ull C ( int n, int m ) {
ull ans = 1;
for ( int i = 1; i <= m; ++i )
ans = ans * ( n - i + 1 ) / i;
return ans;
}
ull h[ maxn + 10 ];
void Catalan () {
h[ 0 ] = 1, h[ 1 ] = 1;
for ( int i = 2; i <= maxn; ++i )
for ( int j = 0; j <= i; ++j )
h[ i ] += h[ j ] * h[ i - j - 1 ];
}
int main () {
#ifdef LOCAL
freopen ( "in", "r", stdin );
// freopen("out","w",stdout);
#endif
int n, ks = 1;
Catalan ();
while ( ~scanf ( "%d", &n ) && ( n != -1 ) ) {
printf ( "%d %d %llu\n", ks++, n, h[ n ] * 2 );
}
return 0;
}