7_7_2013 D.Brackets

Problem D: Brackets

Time Limit: 1 Sec   Memory Limit: 32 MB
Submit: 70   Solved: 23
[ Submit][ Status][ Web Board]

Description

This year MK is 5 years old. So he decides to learn some arithmetic. But he was confused by how to write the brackets. He has already known that the brackets should match when writing them correctly. Such as ()(()) is correct but ())( is not.

The problem is that, if there are N pairs of brackets, how many ways that MK can write them correctly? 

Input

There are several test cases. Each case contains a number N (1 <= N <= 1000) indicating the pairs of brackets.

Output

For each case, please output the answer mod 1,000,000,007.

Sample Input

5 7

Sample Output

42 429
#include <iostream>
#include <stdio.h>
#define NUM 1000000007
using namespace std;
long long int a[1010];
int
main()
{
    int n;
    a[0]=1;
    for(int i = 1; i <= 1000; i++) {
        for(int j = 0; j < i; j++) {
            a[i]=a[i]+a[j]*a[i-j-1]%NUM;
            a[i]=a[i]%NUM;
        }
    }
 //cout<<a[1]<<endl<<a[2]<<endl<<a[3]<<endl<<a[4]<<endl;

while(cin>>n){
        cout<<a[n]<<endl;
    }
    return 0;
}
說好的

卡特兰数

just 坑爹 比賽的時候用的h(n)=h(n-1)*(4*n-2)/(n+1);這個遞推公式,這個是不適合大數取模運算的

你可能感兴趣的:(7_7_2013 D.Brackets)