上海金马五校DHUOJ(King Is a Dull Boy)

Problem A : King Is a Dull Boy


Submit 

Time Limit: 3 s

Description

King is a dull boy and not good at math. One day he met a simple problem but couldn’t find the answer, so he asked you for help. Here is the question.

Given n pairs of parentheses (‘(’ and ‘)’) and m pairs of square brackets (‘[’ and ‘]’), can you find the number of all well-formed expressions of brackets?

For example, if n = 1 and m = 1, there are totally 4 different well-formed expressions of brackets,

“([])”, “()[]”, “[()]” and “[]()”.


Note that expressions like “([]”, "[)", "([)]" or “[(])” are not well-formed.

 

Input

There are several test cases, each of which consists of two non-negative integers n and m, where 0 ≤ n + m ≤ 8.

 

 

Output

For each test case, output the number of all well-formed expressions of brackets.

 

 

Sample Input

 

1 1
2 0

 

Sample Output

 

4
2

 


Author: Sherry

题意:输入一个n和一个m,表示n个()和m个[]组成的串,问有多少种是合法的?

不会卡特兰数,数据不大 就直接暴力打表了

用一个栈判断是否合法,把结果都打出来

#include <bits/stdc++.h>
using namespace std;
int mp[10][10];
int main()
{
    mp[0][0]=0;
mp[0][1]=1;
mp[0][2]=2;
mp[0][3]=5;
mp[0][4]=14;
mp[0][5]=42;
mp[0][6]=132;
mp[0][7]=429;
mp[0][8]=1430;
mp[1][0]=1;
mp[1][1]=4;
mp[1][2]=15;
mp[1][3]=56;
mp[1][4]=210;
mp[1][5]=792;
mp[1][6]=3003;
mp[1][7]=11440;
mp[2][0]=2;
mp[2][1]=15;
mp[2][2]=84;
mp[2][3]=420;
mp[2][4]=1980;
mp[2][5]=9009;
mp[2][6]=40040;
mp[3][0]=5;
mp[3][1]=56;
mp[3][2]=420;
mp[3][3]=2640;
mp[3][4]=15015;
mp[3][5]=80080;
mp[4][0]=14;
mp[4][1]=210;
mp[4][2]=1980;
mp[4][3]=15015;
mp[4][4]=100100;
mp[5][0]=42;
mp[5][1]=792;
mp[5][2]=9009;
mp[5][3]=80080;
mp[6][0]=132;
mp[6][1]=3003;
mp[6][2]=40040;
mp[7][0]=429;
mp[7][1]=11440;
mp[8][0]=1430;
int n,m;
while(cin>>n>>m)
{
    cout<<mp[n][m]<<endl;
}
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值