Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
MREPLBRC - Counting The Way of Bracket Replacement |
English | Vietnamese |
A regular bracket sequence is a string of characters consisting only of opening and closing brackets, and satisfying the following conditions:
- An empty string is a regular bracket sequence.
- If A is a regular bracket0sequence, then (A), [A] and {A} are also regular bracket sequences.
- If A and B are regular bracket sequences, then AB is also a regular bracket sequence.
For example, the sequences [({})], [](){} and [{}]()[{}] are regular, but the sequences [({{([, []({)} and [{}])([{}] are not.
Ivica has found a string which looks like it could be a regular bracket sequence. Some of the characters have become smudged and illegible, and could have been any character.
Write a program that calculates how many ways the illegible characters in the string can be replaced by brackets so that the result is a regular bracket sequence. This number can be very large, so output only its last 5 digits.
Input
The first line contains an even integer N (2 ≤ N ≤ 200), the length of the string.
The second line contains the string. Illegible characters are represented by the '?' character.
Output
Output the number of regular bracket sequences the string could have read.
Sample
Input: 6 ()()() Output: 1
Input: 10 (?([?)]?}? Output: 3
Input: 16 ???[???????]???? Output: 92202
In the second example, the three matching regular bracket sequences are ({([()])}), ()([()]{}) and ([([])]{}).
Được gửi lên bởi: | psetter |
Ngày: | 2009-03-09 |
Thời gian chạy: | 1s |
Giới hạn mã nguồn: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Ngôn ngữ cho phép: | Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET |
Nguồn bài: | COCI 1th 07 |
hide comments
2020-04-02 10:52:42
phải cout như bạn dưới mới AC nhé |
|
2011-06-08 14:31:15 TMTB
test ra số 0 đằng trước nè: 50 ([[[???[]?[??][??]?{??({})]??{[]}?{?????}(?()???{? kq: 00004 Last edit: 2011-06-08 14:32:04 |
|
2011-06-07 19:30:44 1212
Cho em xin test mà ra kết quả có mấy số 0 ở đầu được ko ạ và cho em biết trước kq của test đó luôn? |
|
2010-03-30 13:53:48 Trần Hải Ðãng
Đề này dịch không thật tốt, nếu muốn AC cần lưu ý nếu là kết quả gốc là 15 thì in ra 15, nếu là 100015 thì in ra 00015 |
|
2009-06-08 02:52:18 Pein
Chỉ hiện 5 chữ số cuối cùng. <- Đề ác quá :D |