F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Brackets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1780    Accepted Submission(s): 504


Problem Description
We give the following inductive definition of a ¡°regular brackets¡± sequence:
¡ñ the empty sequence is a regular brackets sequence,
¡ñ if s is a regular brackets sequence, then (s) are regular brackets sequences, and
¡ñ if a and b are regular brackets sequences, then ab is a regular brackets sequence.
¡ñ no other sequence is a regular brackets sequence

For instance, all of the following character sequences are regular brackets sequences:
(), (()), ()(), ()(())
while the following character sequences are not:
(, ), )(, ((), ((()

Now we want to construct a regular brackets sequence of length $n$, how many regular brackets sequences we can get when the front several brackets are given already.
 

Input
Multi test cases (about $2000$), every case occupies two lines.
The first line contains an integer $n$.
Then second line contains a string str which indicates the front several brackets.

Please process to the end of file.

[Technical Specification]
$1 \leq n \leq 1000000$
str contains only '(' and ')' and length of str is larger than 0 and no more than $n$.
 

Output
For each case£¬output answer % $1000000007$ in a single line.
 

Sample Input
4 () 4 ( 6 ()
 

Sample Output
1 2 2
 

Hint
For the first case the only regular sequence is ()().
For the second case regular sequences are (()) and ()().
For the third case regular sequences are ()()() and ()(()).
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:40:39, Gzip enabled