题解:神奇算法从来不死,玄学%%%
#include<cstdio> #include<iostream> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> typedef long long ll; using namespace std; const int N=1000003; const int mod=1000000007; int ans,n,k,a[N],tot; char s[N]; int main(){ scanf("%d %d",&n,&k); a[0]=1; for(int i=1;i<=n;i++) a[i]=(a[i-1]<<1)%mod;//cout<<a[i]<<endl; scanf("%s",s+1); for(int i=n;i>=1;i--){ if(s[i]==‘B‘){ //cout<<i<<tot<<ans<<endl; ++tot; if(tot>k){ ans=(ans+a[i])%mod; tot--; } else continue; } tot=max(0,tot-1); } printf("%d\n",ans%mod); return 0; }
原文:https://www.cnblogs.com/wuhu-JJJ/p/11762306.html