CF1015F.Bracket Substring

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a bracket sequence ss (not necessarily a regular one). A bracket sequence is a string containing only characters '(' and ')'.

A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.

Your problem is to calculate the number of regular bracket sequences of length 2n2n containing the given bracket sequence ss as a substring (consecutive sequence of characters) modulo 109+710^9+7 (10000000071000000007).

给你一个括号序列 ss(不一定是合法的)。括号序列是指仅由字符 '(' 和 ')' 组成的字符串。

合法括号序列(regular bracket sequence)是指:通过在原序列的字符之间插入字符 '1' 和 '+',可将其转化为一个正确的算术表达式。例如,括号序列 "()()" 和 "(())" 是合法的(对应的表达式分别为 "(1)+(1)" 和 "((1+1)+1)"),而 ")("、"(" 和 ")" 则不是合法的。

你的任务是:计算长度为 2n2n 的合法括号序列中,包含给定括号序列 ss 作为子串(即连续的字符序列)的个数,并对 109+710^9+7(即 10000000071000000007)取模。

输入格式

The first line of the input contains one integer nn (1≤n≤1001 \le n \le 100) — the half-length of the resulting regular bracket sequences (the resulting sequences must have length equal to 2n2n).

The second line of the input contains one string ss (1≤∣s∣≤2001 \le |s| \le 200) — the string ss that should be a substring in each of the resulting regular bracket sequences (∣s∣|s| is the length of ss).

输入的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 表示所生成的合法括号序列的半长(即生成的序列长度必须等于 2n2n)。

输入的第二行包含一个字符串 ss(1≤∣s∣≤2001 \le |s| \le 200)—— 字符串 ss 必须是每个所生成的合法括号序列的子串(其中 ∣s∣|s| 表示字符串 ss 的长度)。

输出格式

Print only one integer — the number of regular bracket sequences containing the given bracket sequence ss as a substring. Since this number can be huge, print it modulo 109+710^9+7 (10000000071000000007).

仅输出一个整数——包含给定括号序列 ss 作为子串的合法括号序列的数量。由于该数量可能非常大,请对 109+710^9+7(即 10000000071000000007)取模后输出。

输入输出样例

  • 输入#1

    5
    ()))()

    输出#1

    5
  • 输入#2

    3
    (()

    输出#2

    4
  • 输入#3

    2
    (((

    输出#3

    0

说明/提示

All regular bracket sequences satisfying the conditions above for the first example:

  • "(((()))())";
  • "((()()))()";
  • "((()))()()";
  • "(()(()))()";
  • "()((()))()".

All regular bracket sequences satisfying the conditions above for the second example:

  • "((()))";
  • "(()())";
  • "(())()";
  • "()(())".

And there is no regular bracket sequences of length 44 containing "(((" as a substring in the third example.

第一个样例中满足上述条件的所有合法括号序列:

  • "(((()))())";
  • "((()()))()";
  • "((()))()()";
  • "(()(()))()";
  • "()((()))()".

第二个样例中满足上述条件的所有合法括号序列:

  • "((()))";
  • "(()())";
  • "(())()";
  • "()(())".

第三个样例中,不存在长度为 44 且包含子串 "(((" 的合法括号序列。

输入解题思路,AI测评打分。不知道怎么写?

首页