#P7914. [CSP-S 2021] 括号序列

    ID: 9013 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2021O2优化区间 DPCSP-S 提高级

[CSP-S 2021] 括号序列

Problem Description

Little w encountered such a problem in a contest: given a valid bracket sequence of length nn, where some positions are already fixed and some are not, find how many such bracket sequences there are.

The battle-hardened little w solved it instantly. Not only that, he also felt that using such a simple template problem in an official contest was too easy, so he strengthened the problem and casually threw it to little c.

Specifically, little w defines a “super bracket sequence” as a string consisting of characters (, ), and *. For a given constant kk, the definition of a “valid super bracket sequence” is as follows:

  1. () and (S) are both valid super bracket sequences, where S is any non-empty string consisting only of no more than k\bm{k} characters * (the S in the next two rules has the same meaning).
  2. If both strings A and B are valid super bracket sequences, then AB and ASB are also valid super bracket sequences, where AB means concatenating string A and string B.
  3. If string A is a valid super bracket sequence, then (A), (SA), and (AS) are also valid super bracket sequences.
  4. All valid super bracket sequences can be obtained using the above 3 rules.

For example, if k=3k = 3, then the string ((**()*(*))*)(***) is a valid super bracket sequence, but *(), (*()*), ((**))*), and (****(*)) are not. In particular, the empty string is also not considered a valid super bracket sequence.

Now you are given a super bracket sequence of length nn, where some positions have already been fixed, and the other positions are not fixed (denoted by ?). Little w wants to compute: in how many ways can we determine all the unknown characters one by one so that the resulting string is a valid super bracket sequence?

Poor little c cannot solve this problem, so he has to ask you for help.

Input Format

The first line contains two positive integers n,kn, k.

The second line contains a string SS of length nn, consisting only of (, ), *, and ?.

Output Format

Output a non-negative integer, representing the answer modulo 109+7{10}^9 + 7.

7 3
(*??*??

5

10 2
???(*??(?)

19

见附件中的 bracket/bracket3.in
见附件中的 bracket/bracket3.ans
见附件中的 bracket/bracket4.in
见附件中的 bracket/bracket4.ans

Hint

[Sample Explanation #1]

The following solutions are valid:

(**)*()
(**(*))
(*(**))
(*)**()
(*)(**)

[Constraints]

Test Point ID nn \le Special Property
131 \sim 3 1515 None
484 \sim 8 4040
9139 \sim 13 100100
141514 \sim 15 500500 The string SS contains only the character ?
162016 \sim 20 None

For 100%100\% of the testdata, 1kn5001 \le k \le n \le 500.

Translated by ChatGPT 5