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

Copy
  1. ab
output

Copy
  1. 1
input

Copy
  1. aab
output

Copy
  1. 3
Note

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

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

从后向前 遍历

每个a都会把它后边的b变到后边 且乘二

而每个a后边b的个数 即为当前a变化的次数

  1. #include <bits/stdc++.h>
  2. #define mem(a, b) memset(a, b, sizeof(a))
  3. using namespace std;
  4. typedef long long LL;
  5. const int maxn = , INF = 0x7fffffff;
  6. const int MOD = 1e9 + ;
  7. int n;
  8. string str;
  9.  
  10. int main()
  11. {
  12.  
  13. cin >> str;
  14. int len = str.size();
  15. int ans = , cnt = ;
  16. for(int i = len - ; i >= ; i--)
  17. {
  18. if(str[i] == 'b')
  19. cnt++;
  20. else
  21. {
  22. ans = (ans + cnt) % MOD;
  23. cnt = (cnt * ) % MOD;
  24. }
  25.  
  26. }
  27. cout << ans << endl;
  28.  
  29. return ;
  30. }
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

Copy
  1. ab
output

Copy
  1. 1
input

Copy
  1. aab
output

Copy
  1. 3
Note

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

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

Minimum number of steps CodeForces - 805D(签到题)的更多相关文章

  1. Codeforces 805D - Minimum number of steps

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

  2. 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 ...

  3. Minimum number of steps 805D

    http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second ...

  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 805 D. Minimum number of steps(数学)

    题目链接:http://codeforces.com/contest/805/problem/D 题意:只有一个操作就是将ab变成bba直到不能变为止,问最少边几次. 题解:这题可以多列几组来找规律, ...

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

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

随机推荐

  1. 关于NETCORE中的捆绑与最小化 以及与CDN连用

    参考文档:MSDN   Bundling and minification in ASP.NET Core 细说ASP.NET Core静态文件的缓存方式

  2. 六、Xadmin忘记密码

    1.如果用的是django自带的User模块,忘记了超级用户的密码,可以通过以下方法找回密码: 终端进入项目根目录,然后输入如下命令: python manage.py shell 然后在python ...

  3. portscaner 多线程、多协程并发端口扫描

    import socket,time,re,sys,os,threading import gevent from gevent import monkey monkey.patch_all() so ...

  4. 我的2017&2018

    最近项目进入验收阶段,所以上班没那么忙碌了,但是怎么说呢,我可能天生是闲不住的主,觉得浑身不自在(我这样的人是不是特别不会享福),此处应该有个笑脸哈. 翻看了博客园好几个大牛写的技术文章,感慨大牛不愧 ...

  5. 翻转一个数组(c++实现)

    反转一个数组: 其实STL中的vector有一个reverse函数便可以使用. #include<iostream> using namespace std; int* ReverseAr ...

  6. 新浪2017校园招聘---C++后台研发

    一共10道题目,难度不大,就是题量大,时间短. 1.  编程        写一个函数,求出一字符串的所有排列. 2.  编程        实现一个在32位系统下把字符串转换成浮点数的函数 floa ...

  7. Python_查找员工信息-48

    ''' 查找出userinfo文件中年龄大于22岁的员工姓名和年龄 1,Alex,22,13651054608,IT 2,Egon,23,13304320533,Tearcher 3,nezha,25 ...

  8. Graph Without Long Directed Paths CodeForces - 1144F (dfs染色)

    You are given a connected undirected graph consisting of nn vertices and mm edges. There are no self ...

  9. Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  10. [iOS]一行代码集成空白页面占位图(基于runtime+MJRefresh思想)

    2018年01月03日阅读 2472   [iOS]一行代码集成空白页面占位图(基于runtime+MJRefresh思想) LYEmptyView 此框架是本人在5,6个月前,公司启动新项目的时候, ...