CF804B Minimum number of steps

code: 

#include <bits/stdc++.h> 
#define N 2000000 
#define ll long long  
#define mod 1000000007 
#define setIO(s) freopen(s".in","r",stdin) 
using namespace std; 
char S[N]; 
int main() 
{
    // setIO("input");        
    int i,j,n; 
    ll ans=0,pre=0;    
    scanf("%s",S+1);    
    n=strlen(S+1);      
    for(i=n;i>=1;--i) 
    {
        if(S[i]=='b') 
        {
            ++pre; 
        } 
        else 
        {
            ans=(ans+pre)%mod;  
            pre=2ll*pre%mod;       
        }
    }
    printf("%lld
",ans); 
    return 0; 
}

  

原文地址:https://www.cnblogs.com/guangheli/p/11619860.html