思路:
惊讶的发现,所有的蓝球的消除都是独立的;
对于在栈中深度为i的蓝球消除需要2^i次操作;
代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; long long ans=0; int main() { // freopen("ball.in","r",stdin); // freopen("ball.out","w",stdout); int n;char ch[105]; long long count=1; scanf("%d",&n); scanf("%s",ch); for(int i=0;i<n;i++) { if(ch[i]=='B') ans+=count; count<<=1; } printf("%lld ",ans); return 0; }