A1106 | [COCI-2007_2008-contest1]#6 ZAPIS
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
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 bracket-sequence, 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 [({})], [](){} i [{}]()[{}] 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.
• An empty string is a regular bracket-sequence.
• If A is a regular bracket-sequence, 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 [({})], [](){} i [{}]()[{}] 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.
输入格式
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.
The second line contains the string. Illegible characters are represented by the '?' character.
输出格式
Output the number of regular bracket-sequences the string could have read.
输入输出样例
输入 #1
6 ()()()
输出 #1
1
输入 #2
10 (?([?)]?}?
输出 #2
3
输入 #3
16 ???[???????]????
输出 #3
92202
In the second example, the three matching regular bracket-sequences are ({([()])}), ()([()]{})
and ([([])]{}).
and ([([])]{}).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted