DP:
#include <bits/stdc++.h>
using namespace std;
int p[20][20];
int main() {
int n;
cin >> n;
for (int i = 0; i <= n; ++i) {
p[i][0] = 1;
}
for (int j = 1; j <= n; ++j) {
for (int i = 0; i <= n; ++i) {
if (i >= 1) {
p[i][j] = p[i - 1][j] + p[i + 1][j - 1];
}
if (i == 0) {
p[i][j] = p[i + 1][j - 1];
}
}
}
cout << p[0][n] << endl;
return 0;
}
卡特兰数:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define ULL unsigned long long
int n;
int p[20];
int main() {
cin >> n;
p[0] = p[1] = 1;
for (int i = 2; i <= n; ++i) {
for (int j = 0; j < n; ++j) {
p[i] += p[j] * p[i - j - 1];
}
}
cout << p[n] << endl;
return 0;
}