[第一次训练]Brackets
来源:互联网 发布:js获取元素的父节点 编辑:程序博客网 时间:2024/06/07 11:54
Brackets
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
解题报告
此题为Catalan number(卡特兰数)的题目,此题套用通用公式令h(0)=1,h(1)=1,catalan数满足递推式h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0)(n>=2),,然后在边乘边模即可。 代码如下:
#include<stdio.h>const int maxn = 1000 + 5;const int MOD = 1000000007;/*Catalan number*/int n;long long f[maxn];int main() { f[0] = 1; for(int i = 1; i <= 1000; i++) { for(int j = 0; j < i; j++) { f[i] += f[j] * f[i - j - 1] % MOD; f[i] %= MOD; } } while(scanf("%d", &n) == 1) { printf("%I64d\n", f[n]); } return 0;}
- [第一次训练]Brackets
- 动态规划训练9 [Brackets POJ
- 动态规划训练10 [Coloring Brackets CodeForces
- [第一次训练]Eming
- [第一次训练]Arithmetic Progression
- [第一次训练]Function
- 蓝桥杯训练第一次作业
- Brackets
- Brackets
- Brackets
- Brackets
- Brackets
- Brackets
- brackets
- Brackets
- 2013第一次组队训练赛
- 深入word2vec(1) - 第一次训练
- IMWeb训练营作业第一次
- BigDecimal
- Struts2接收参数的几种方式
- LinkList的create,delete,print
- 加减乘除Decimal
- c fseek()函数使用
- [第一次训练]Brackets
- 软件级负载均衡器(LVS/HAProxy/Nginx)的特点简介和对比
- 使用JDK中的安全包对数据进行加解密
- 利用JNI技术在Android中调用、调试C++代码
- boost库在工作(32)网络服务端之二
- 转 c++引用参数深入分析
- Linux 上Oracle RAC 10g 升级到 Oracle RAC 11g
- 一道将汉字和数字关联起来的题
- uva10152