标签:blog io os for 2014 sp log on c
题目:在圆内有2n个点,求不相交的连接弦的方法数。
分析:组合,计数,卡塔兰数。
说明:利用组合数递推求卡塔兰数。
#include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int f[22][22] = {0}; int main() { for (int i = 0 ; i <= 20 ; ++ i) f[i][0] = f[i][i] = 1; for (int i = 1 ; i <= 20 ; ++ i) for (int j = 1 ; j < i ; ++ j) f[i][j] = f[i-1][j]+f[i-1][j-1]; int n,t = 0; while (cin >> n) { if (t ++) cout << endl; cout << f[2*n][n]/(n+1) << endl; } return 0; }
标签:blog io os for 2014 sp log on c
原文地址:http://blog.csdn.net/mobius_strip/article/details/39234055