D. Minimum number of steps
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.

The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.

Input

The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.

Output

Print the minimum number of steps modulo 109 + 7.

Examples
input
ab
output
1
input
aab
output
3
Note

The first example: "ab"  →  "bba".

The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".

题意:

对于给定字符串,我们可将其中的子串“ab”替换成“bba”,直到没有子串“ab”。

求操作次数。

由题意可知,a后的一个b会变成a前的两个b。

我们可以反向遍历,记录b的个数,每遇到a做一次操作。b*=2.继续。

附AC代码:

 #include<bits/stdc++.h>
using namespace std; const int mod=1e9+; int main(){
string s;
cin>>s;
long long ans=,cnt=;
int n=s.size();
for(int i=n-;i>=;i--){
if(s[i]=='b')
cnt++;
else{
ans+=cnt;
ans%=mod;
cnt=cnt*%mod;
}
}
cout<<ans%mod<<endl;
return ;
}

CF-805D的更多相关文章

  1. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  4. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  5. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  6. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  7. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  8. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  9. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  10. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

随机推荐

  1. ubuntu 14.04 下利用apt-get方式安装opencv

    转载,请注明出处:http://blog.csdn.net/tina_ttl 目录(?)[+] 标签(空格分隔): Linux学习 OpenCV ubuntu 1404 下利用apt-get方式安装O ...

  2. js event 的target 和currentTarget

    target  点击的实际tag currentTarget 绑定事件的target

  3. 基于EfCore的一个多租户Demo

    六月份如愿的转入了架构组,先上手搞了个CI服务器,把架构组的几个项目撸到上面去了.效果不错,接着就把其他两个项目组有单元测试的项目撸上去了,在桌子上放了个显示器当大屏用. 因为公司准备进行一个大的系统 ...

  4. MySQL 存储过程 (3)

    以下介绍下像数据库循环插入数据操作 第一步:建立存储过程用到的信息表

  5. NoSQL的四大类型

    1 键值数据库 相关产品:Redis.Riak.SimpleDB.Chordless.Scalaris.Memcached 应用:内容缓存 优点:扩展性好.灵活性好.大量写操作时性能高 缺点:无法存储 ...

  6. java内部类和静态内部类的区别

    1 相同点 使用的时候,import的时候,除了包名,还要带外部类. 2 不同点 2.1 对象创建的方式不同 静态内部类创建对象的时候,独立于外部类及其对象,就好像它是一个独立的类,可以和外部类一样使 ...

  7. 从模版生成 uri Golang 的 html/template 包不太适合于这种情况

    模板 - Go/Golang 框架 Echo 文档 http://go-echo.org/guide/templates/ Templates | Echo - High performance, m ...

  8. iOS反射机制:objc_property_t的使用

    #import <objc/runtime.h> 需要导入这个头文件. 动态获取一个自定义类对象中的所有属性 - (NSDictionary *)allProperties { NSMut ...

  9. MATLAB 2013b .m 文件关联

    使用绿色版的MATLAB无法自动关联.m文件,在网上查到的解决办法是,在MATLAB里运行如下命令: cwd=pwd; cd([matlabroot '\toolbox\matlab\winfun\p ...

  10. 理解vue ssr原理,自己搭建简单的ssr框架

    前言 大多数Vue项目要支持SSR应该是为了SEO考虑,毕竟对于WEB应用来说,搜索引擎是一个很大的流量入口.Vue SSR现在已经比较成熟了,但是如果是把一个SPA应用改造成SSR应用,成本还是有些 ...