Brackets解题报告

题目摘要: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;

}

解题感想:开始用递归的公式做的,数据一大就递不出结果了,感觉不会再爱递归了……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值