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的字符串,把里面的ab替换为bba直到没有ab了为止,问最少多少步
思路,最后肯定变成bbb...bbbaaa...aaa的形式,所以不管怎么变步数应该是一样的。分析发现每个a能把他后边的b变成2个b,而a要变的次数一定是后面b的个数,于是从后面开始处理,统计b的数量即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long
const LL mod=1e9+7; char s[1000006];
int main()
{
scanf("%s",s);
int k=strlen(s);
LL cnt=0;
LL ans=0;
int x=0;
for(int i=k-1; i>=0; i--)
{
if(s[i]=='b')
{
cnt++;
}
else
{
ans+=cnt;
ans%=mod;
cnt*=2;
cnt%=mod;
} }
printf("%lld\n",ans);
return 0;
}




Codeforces805D. Minimum number of steps 2017-05-05 08:46 240人阅读 评论(0) 收藏的更多相关文章

  1. Number Sequence 分类: HDU 2015-06-19 20:54 10人阅读 评论(0) 收藏

    Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...

  2. HDU1349 Minimum Inversion Number 2016-09-15 13:04 75人阅读 评论(0) 收藏

    B - Minimum Inversion Number Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  3. Case of the Zeros and Ones 分类: CF 2015-07-24 11:05 15人阅读 评论(0) 收藏

    A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...

  4. ZOJ2418 Matrix 2017-04-18 21:05 73人阅读 评论(0) 收藏

    Matrix Time Limit: 2 Seconds      Memory Limit: 65536 KB Given an n*n matrix A, whose entries Ai,j a ...

  5. HDU2577 How to Type 2016-09-11 14:05 29人阅读 评论(0) 收藏

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏

    FatMouse and Cheese Problem Description FatMouse has stored some cheese in a city. The city can be c ...

  7. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 175人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  8. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 174人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  9. Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏

    Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...

随机推荐

  1. How to Pronounce the Word THEM

    How to Pronounce the Word THEM Share Tweet Share Tagged With: THEM Reduction Study the THEM reductio ...

  2. 【343】MathJax、LaTex、Mathml 数学公式

    参考:cnblog中添加数学公式支持 分类参考: 1. 基本功能 MathJax 我的LaTeX入门 MathJax basic tutorial and quick reference 分段函数:矩 ...

  3. git cherry-pick用法

    场景: 如果你的应用已经发布了一个版本2.0, 代码分支叫release-2.0, 现在正在开发3.0, 代码的分支叫dev-3.0. 那么有一天产品说, 要把正在开发的某个特性提前上线, 也就是说要 ...

  4. 《Blue Flke》第一次作业:团队亮相

    1.队名:Blue Flke 团队格言:决心是成功的力量,耐心是成功的保障. 2.团队成员组成:  201571030129/ 王胜海 (组长)  201571030126/ 妥志福 20157103 ...

  5. TOMCAT Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

    十二月 31, 2014 2:32:45 下午 org.apache.coyote.http11.AbstractHttp11Processor process信息: Error parsing HT ...

  6. linux分区之gpt(大于2T的分区)

    1.文件系统限制: ext3块尺寸 最大文件尺寸 最大文件系统尺寸1KiB  16GiB  2TiB2KiB  256GiB  8TiB4KiB  2TiB  16TiB8KiB  16TiB  32 ...

  7. [leetcode]269. Alien Dictionary外星字典

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  8. [leetcode]299. Bulls and Cows公牛和母牛

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...

  9. 版本号比较函数-js

    面试前,让做的一个版本号比较函数. <script type="text/javascript"> var v1=prompt("请输入第一个版本号" ...

  10. python性能测试大致计划

      hi guy: 如果注意到创建时间,那就对了.这份文章,是我学习Python一个月以后动手写的.   写下这份计划以后,只完成了第一步,其中磕磕绊绊编写代码的过程,很大一部分时间是完全用txt写的 ...