【題解】UVA 991 Safe Salutations

【題目敘述】https://vjudge.net/problem/UVA-991
【解題想法】卡塔蘭數

#include <iostream>
using namespace std;
const int maxn = 25;
int C[maxn][maxn];
 
int main() {
    for (int i=0; i<maxn; i++){
        C[i][0] = 1;
        C[i][i] = 1;
    }
    for (int i=1; i<maxn; i++){
        for (int j=1; j<i; j++){
            C[i][j] = C[i-1][j] + C[i-1][j-1];
        }
    }
    int N;
    bool first = true;
    while (cin >> N){
        if (N == 0) break;
        if (first) first = false;
        else cout << "\n";
        cout << C[2*N][N] / (N+1) << "\n";
    }
    return 0;
}
分享本文 Share with friends