CF785D.Anton and School - 2
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)).
On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met:
- It is not empty (that is n ≠ 0).
- The length of the sequence is even.
- First
charactes of the sequence are equal to "(". - Last
charactes of the sequence are equal to ")".
For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS.
Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted.
Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7.
Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it!
你可能知道,安东要去上学。安东学习的课程之一是“括号学”(Bracketology)。在“括号学”课上,学生们通常学习由圆括号(即字符 "(" 和 ")"(不带引号))组成的各类序列。
在最近的一节课上,安东学习了正则简单括号序列(RSBS)。一个长度为 $ n $ 的括号序列 $ s $ 被称为 RSBS,当且仅当满足以下条件:
- 它非空(即 $ n \neq 0 $);
- 序列长度为偶数;
- 序列的前 $ \frac{n}{2} $ 个字符均为
"("; - 序列的后 $ \frac{n}{2} $ 个字符均为
")"。
例如,序列 "((()))" 是一个 RSBS,但序列 "((())" 和 "(())()" 不是 RSBS。
安东的老师——叶莲娜·伊万诺夫娜——给他布置了如下家庭作业:给定一个括号序列 $ s ,求其∗∗不同的子序列∗∗中,有多少个是RSBS。注意: s $ 的一个子序列是指从 $ s $ 中删除若干字符(可为零个)后得到的字符串;若两个子序列所删除的位置集合不同,则认为它们是不同的子序列。
由于答案可能非常大,而安东的老师不喜欢大数,因此她要求安东将答案对 $ 10^9 + 7 $ 取模后提交。
安东思考这道题想了很长时间,却仍不知如何求解。请帮助安东解决这个问题,并编写一个程序来计算该答案!
输入格式
The only line of the input contains a string s — the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000.
输入仅包含一行,为一个字符串 s——即安东作业中的括号序列。该字符串仅由字符 ( 和 )(不含引号)组成。保证字符串非空,且其长度不超过 200000。
输出格式
Output one number — the answer for the task modulo 109 + 7.
输出一个数字——该任务答案对 109+7 取模的结果。
输入输出样例
输入#1
)(()()
输出#1
6
输入#2
()()()
输出#2
7
输入#3
)))
输出#3
0
说明/提示
In the first sample the following subsequences are possible:
- If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())".
- If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()".
- If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()".
- If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()".
- If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()".
- If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()".
The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6.
在第一个样例中,以下子序列是可能的:
- 如果删除位置 1 和 5 处的字符(位置编号从 1 开始),我们将得到子序列 "(())"。
- 如果删除位置 1、2、3 和 4 处的字符,我们将得到子序列 "()"。
- 如果删除位置 1、2、4 和 5 处的字符,我们将得到子序列 "()"。
- 如果删除位置 1、2、5 和 6 处的字符,我们将得到子序列 "()"。
- 如果删除位置 1、3、4 和 5 处的字符,我们将得到子序列 "()"。
- 如果删除位置 1、3、5 和 6 处的字符,我们将得到子序列 "()"。
其余子序列均不是 RSBS。因此我们共得到 6 个不同的 RSBS 子序列,答案为 6。
输入解题思路,AI测评打分。不知道怎么写?