http://codeforces.com/contest/805/problem/D

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 modulo109 + 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 from1 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

分析:将字符ab 替换成 bba 可以看成 a 向右移动一位, ab 中的 b 后增加一个 b

    每次将a 字符移动到所有b字符 的右端, 下一个a右边的b就多了一倍, 所以每遇到一个a 加上右边的b,然后更新右边的b为2*b

 #include <bits/stdc++.h>
using namespace std;
#define ll long long const ll mod = 1e9 + ;
// "ab" ?→? "bba".
// "aab" ?→? "abba" ?→? "bbaba"?→? "bbbbaa". int main(){
string str;
while(cin >> str){
//cout << str << endl;
ll b = ;
ll ans = ;
for(ll i = str.length() - ; i >= ; i--){
// cout << "b " << b<< endl;
if(str[i] == 'b')
b++;
//cout << "b " << b<< endl;
if(str[i] == 'a'){
ans += b%mod;
//cout << ans << endl;
ans %= mod;
b *= ;
b %= mod;
}
}
cout << ans% mod << endl;
}
}

Minimum number of steps 805D的更多相关文章

  1. Codeforces 805D - Minimum number of steps

    805D - Minimum number of steps 思路:简单模拟,a每穿过后面一个b,b的个数+1,当这个a穿到最后,相当于把它后面的b的个数翻倍.每个a到达最后的步数相当于这个a与它后面 ...

  2. Minimum number of steps CodeForces - 805D(签到题)

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  3. Codeforces Round #411 div 2 D. Minimum number of steps

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  4. codeforce 804B Minimum number of steps

    cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each ...

  5. Codeforces805D. Minimum number of steps 2017-05-05 08:46 240人阅读 评论(0) 收藏

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  6. 【codeforces 805D】Minimum number of steps

    [题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...

  7. Codeforces 805D/804B - Minimum number of steps

    传送门:http://codeforces.com/contest/805/problem/D 对于一个由‘a’.‘b’组成的字符串,有如下操作:将字符串中的一个子串“ab”替换成“bba”.当字符串 ...

  8. 【推导】Codeforces Round #411 (Div. 1) B. Minimum number of steps

    最后肯定是bbbb...aaaa...这样. 你每进行一系列替换操作,相当于把一个a移动到右侧. 会增加一些b的数量……然后你统计一下就行.式子很简单. 喵喵喵,我分段统计的,用了等比数列……感觉智障 ...

  9. 【贪心】codeforces D. Minimum number of steps

    http://codeforces.com/contest/805/problem/D [思路] 要使最后的字符串不出现ab字样,贪心的从后面开始更换ab为bba,并且字符串以"abbbb. ...

随机推荐

  1. 把Swift中的String转成NSString ,获取NSString的方法

    1.0 在Swift中的 String 并没有提供什么方法,直接把它自身转变成 Int .Float 等,而在OC中我们就可以这样  "123".integerValue 来获取它 ...

  2. thymeleaf 字面量

  3. Oracle 查询版本号

    select * from v$version; -- 或 select banner from sys.v_$version;

  4. vue--公告轮播

    html:   <div class="news" v-if="news.length > 0" > <ul class="m ...

  5. phpexcel 导入超过26列时的解决方案

    $highestColumn = $sheet->getHighestColumn(); // 取得总列数 ++$highestColumn; for ($row = 5; $row <= ...

  6. Shader基础(渲染管线)

    Shader原理部分 渲染绘图管线流程:     1.顶点处理(坐标系的转换) 一个模型有自身的方向(前方,上方,右方等)和中心点,既本地坐标系: 将这个模型放到场景当中,通过场景中的世界坐标原点和世 ...

  7. js中函数的 this、arguments 、caller,call(),apply(),bind()

    在函数内部有两个特殊的对象,arguments 和 this,还有一个函数对象的属性caller. arguments对象 arguments是一个类似数组的对象,包含着传入函数的所有参数. func ...

  8. asp.net MVC 导出excle(转)

    转载网址: http://www.cnblogs.com/imr3/articles/2856109.html 还是放到自己这边比较保险. ExportExcel Code public FileRe ...

  9. JMeter学习(十六)JMeter测试Java(二)(转载)

    转载自 http://www.cnblogs.com/yangxia-test 实例: 服务为:将输入的两个参数通过IO存入文件: 1.打开MyEclipse,编写Java代码 服务: package ...

  10. 区分action, service和dao

    在这里,我们不仅要处理页面逻辑,还要做业务逻辑,还要做数据访问.比如说: public String addUser() { if(user == null) { return FAIL_NO_USE ...