Red and Blue Balls

题意翻译

## 【题目描述】 一个栈内初始有n个红色和蓝色的小球,请你按照以下规则进行操作 1.只要栈顶的小球是红色的,将其取出,直到栈顶的球是蓝色 2.然后将栈顶的蓝球变成红色 3.最后放入若干个蓝球直到栈中的球数为n 以上3步骤为一次操作 如栈中都是红色球,则操作停止,请问几次操作后停止 ainta出完题发现他自己不能AC所以想请你帮忙 ## 【输入格式】 第一行为一个整数n,表示栈的容量为n 第二行为一个字符串,第i个字符表示自顶向下的第i个球的颜色,R代表红色,B代表蓝色 ## 【输出格式】 一个整数表示操作数 ## 【样例输入】 ### 样例1: 3 RBR ### 样例2: 4 RBBR ## 【样例输出】 样例1:2 样例2:6 ## 【样例解释】 样例1:(如图) 样例2:(如图) ## 【数据范围】 50%的数据,1<=n<=20 100%的数据,1<=n<=50 翻译提供者:leonyy

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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.

输入输出样例

输入样例 #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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF399B/46d99e80a224613ca49d2dd409a2bd590f3a143b.png)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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF399B/ba104f84149ca3428e863eb38f8da803a6fe6f63.png)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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF399B/246415b97c6930634b8753ec3ac33ff3b80befc8.png)