
卡特兰数的应用
//#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 10;
int arr[MAXN] = {1, 1, 2};
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
for(int i = 3; i <= 200; i++)
{
for(int j = 0; j < i; j++)
{
arr[i] += arr[j] * arr[i - j - 1];
arr[i] %= 100;
}
}
int n;
cin>>n;
cout<<arr[n]<<endl;
return 0;
}
本文介绍了一种计算卡特兰数的高效算法,并通过一个C++代码示例展示了如何利用该算法计算一系列卡特兰数。卡特兰数在组合数学中有着广泛的应用,如括号匹配、路径计数等问题。
1065

被折叠的 条评论
为什么被折叠?



