CF399B.Red and Blue Balls
普及/提高-
通过率:0%
时间限制:0.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
用户 ainta 有一叠包含 n 个红球和蓝球的球。他可以执行一种特定操作,该操作会改变栈中球的颜色。
- 当栈顶球为红色时,持续将栈顶球弹出;
- 然后将此时位于栈顶的蓝球替换为一个红球;
- 最后向栈中压入若干蓝球,直至栈中球的总数恢复为 n 个。
若栈中不存在蓝球,则 ainta 无法执行该操作。给定栈的初始状态,ainta 想知道他最多能重复执行多少次该操作。
输入格式
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.
第一行包含一个整数 n(1≤n≤50)—— 表示栈中球的数量。
第二行包含一个字符串 s(∣s∣=n),用于描述栈的初始状态。字符串 s 的第 i 个字符表示第 i 个球的颜色(我们从栈顶到栈底对球进行编号)。若该字符为 "R",则球的颜色为红色;若为 "B",则为蓝色。
输出格式
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.
输出 ainta 最多可以重复执行的操作次数。
请注意,在 C++ 中不要使用 %lld 说明符来读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。
输入输出样例
输入#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.

第一个示例如下图所示。
用户 ainta 执行第一次操作的过程说明:他弹出一个红球,将中间位置球的颜色由蓝色改为红色,并压入一个蓝球。

用户 ainta 执行第二次操作的过程说明:他不弹出任何红球,仅将栈顶球的颜色由蓝色改为红色。

此后,ainta 无法再执行任何操作,因为栈中已无蓝球。ainta 共执行了两次操作,因此答案为 2。
第二个示例如下图所示。蓝色箭头表示一次操作。

输入解题思路,AI测评打分。不知道怎么写?