Brackets解题报告
来源:互联网 发布:淘宝公益宝贝可以买吗 编辑:程序博客网 时间:2024/05/10 08:13
题目摘要:This year MK is 5 years old. So hedecides to learn somearithmetic But he wasconfused by how to write the brackets. He has already known that the bracketsshould match when writing them correctly. Such as “()(())” is correct but “())(”is not.
The problem is that, if there are N pairsof brackets, how many ways that MK can write them correctly?
题目大意:给出N对括号,输出正确的组合方式数
输入输出要求:
Input
There are several test cases. Each casecontains a number N (1 <= N <= 1000) indicating the pairs of brackets.
Output
For each case, please output the answer mod1,000,000,007.
输入输出样例:
Sample Input :
5
7
Sample Output :
42
429
解题思路:结果就是一组卡特兰数,用公式输出结果就行,由于测试的数据很大,所以边乘边模。
代码:
#include<iostream>
using namespace std;
const int maxn=1000+5;
const int MOD=1000000007;
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(cin>>n)
{
cout<<f[n]<<endl;
}
return 0;
}
解题感想:开始用递归的公式做的,数据一大就递不出结果了,感觉不会再爱递归了……
- Brackets解题报告
- 1141 Brackets Sequence 解题报告
- 解题报告: POJ_2955 Brackets DP
- 【Jason's_ACM_解题报告】Brackets sequence
- ***UVa-1626 Brackets sequence ACM解题报告(巧妙地递推+打印)经典的括号 dp题
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- Antiprime解题报告
- expr解题报告
- 华容道解题报告
- tju解题报告
- zju1062/pku1095解题报告
- UsacoGate解题报告 --- 序曲
- E:Could not open lock file /var/lib/dpkg/lock - open (13:Permission denied) E:Unable to lock th
- Hibernate jar包的作用(转)
- 协同培训的开始7-10
- 数据结构排序算法
- python的接口和抽象类
- Brackets解题报告
- 数学之路(3)-机器学习(3)-机器学习算法-SVM[1]
- QT Designer 使用入门例子
- Linux shell-File System1
- DAO中接口作用
- IOS 特性CALayer的使用
- html5画猫全过程svg入门
- lsof与netstat
- 老鸟的Python入门教程