Problem D: Brackets
Time Limit: 1 Sec Memory Limit: 32 MB Submit: 70 Solved: 23 [ ][ ][ ]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#include #define NUM 1000000007using namespace std;long long int a[1010];intmain(){ 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< < < < < < < < >n){ cout< <
說好的
卡特兰数
just 坑爹 比賽的時候用的h(n)=h(n-1)*(4*n-2)/(n+1);這個遞推公式,這個是不適合大數取模運算的