【CF 629C】Famil Door and Brackets(dp,思维)

题目

题目传送门

题面翻译

描述

Family Door 的生日就要到了,Gabi(Family Door的好朋友)想要给他买一个礼物。Gabi决定买一个只包含 ‘(’、‘)’ 的字符串,毕竟 Family Door 最喜欢的字符串是长度为 n n n 的只包含 ‘(’、‘)’ 的字符串。

我们称一个只包含 ‘(’、‘)’ 的字符串“有效”当且仅当:

  1. '(‘的数量等于’)'的数量;
  2. 对于该字符串的任意前缀,均满足’(‘的数量大于等于’)'的数量;

Gabi 买了一个长度为 m m m 的只包含 ‘(’、‘)’ 的字符串 S S S。为了使它的长度达到 n n n ,Gabi要构造两个只包含’(‘、’)'的字符串 P , Q P,Q P,Q,然后将 P , S , Q P,S,Q P,S,Q 顺次连接得到字符串 S ′ S' S

给出Gabi买的字符串 S S S,要使 S ′ S' S 有效,Gabi有多少种构造 P , Q P,Q P,Q 的方案?( P , Q P,Q P,Q都可以为空)。

输入

第一行包括整数 n , m n,m n,m;第二行为长度为 m m m 的字符串 S S S

输出

输出一个正整数,表示构造 P , Q P,Q P,Q 的方案数,答案对 ( 1 0 9 + 7 ) (10^9+7) (109+7) 取模。

数据规模

1 ≤ m ≤ n ≤ 100000 , n − m ≤ 2000 1\leq m\leq n\leq 100000,n-m\leq 2000 1mn100000,nm2000

题目描述

As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n n n more than any other strings!

The sequence of round brackets is called valid if and only if:

  1. the total number of opening brackets is equal to the total number of closing brackets;
  2. for any prefix of the sequence, the number of opening brackets is greater or equal than the number of closing brackets.

Gabi bought a string s s s of length m m m ( m < = n m<=n m<=n ) and want to complete it to obtain a valid sequence of brackets of length n n n . He is going to pick some strings p p p and q q q consisting of round brackets and merge them in a string p + s + q p+s+q p+s+q , that is add the string p p p at the beginning of the string s s s and string q q q at the end of the string s s s .

Now he wonders, how many pairs of strings p p p and q q q<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值