A9452 | Red and Blue Balls
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
User ainta has a stack of $n$ red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack.
- While the top ball inside the stack is red, pop the ball from the top of the stack.
- Then replace the blue ball on the top with a red ball.
- And finally push some blue balls to the stack until the stack has total of $n$ balls inside.
If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply.
- While the top ball inside the stack is red, pop the ball from the top of the stack.
- Then replace the blue ball on the top with a red ball.
- And finally push some blue balls to the stack until the stack has total of $n$ balls inside.
If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply.
输入格式
The first line contains an integer $n$ ( $1<=n<=50$ ) — the number of balls inside the stack.
The second line contains a string $s$ ( $|s|=n$ ) describing the initial state of the stack. The $i$ -th character of the string $s$ denotes the color of the $i$ -th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue.
The second line contains a string $s$ ( $|s|=n$ ) describing the initial state of the stack. The $i$ -th character of the string $s$ denotes the color of the $i$ -th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue.
输出格式
Print the maximum number of operations ainta can repeatedly apply.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输入输出样例
输入 #1
3 RBR
输出 #1
2
输入 #2
4 RBBR
输出 #2
6
输入 #3
5 RBBRR
输出 #3
6
The first example is depicted below.
The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball.
The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red.
From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2.
The second example is depicted below. The blue arrow denotes a single operation.

The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball.
The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red.
From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2.
The second example is depicted below. The blue arrow denotes a single operation.

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted