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. (1)shiro简介和第一个demo

    之前一直在用shiro开发,不过只是会使用,并没有深入了解,最近有时间学习了一下,把最近学习所得分享一下. shiro简介 Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授 ...

  2. 八大排序算法python实现

    一.概述   排序有内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 我们这里说说八大排序就是内部排序. 当 ...

  3. Centos 安装Mongo DB

    NOSQL在很短的时间里使用人数据高涨,这不仅是它提出的一种新存储思想,更是因为它在对大数据做操作的效率,明显高于关系数据库 工具/原料   接入Internet的一台Centos计算机 下载安装文件 ...

  4. LibreOJ 6277 数列分块入门 1(分块)

    题解:感谢hzwer学长和loj让本蒟蒻能够找到如此合适的入门题做. 这是一道非常标准的分块模板题,本来用打标记的线段树不知道要写多少行,但是分块只有这么几行,极其高妙. 代码如下: #include ...

  5. Java的继承与接口

    为什么Java里面只允许单一继承,但允许实现多个接口? 1,为什么不能实现类的多继承?主要是防止多个类有相同的方法名,然而方法体不一样,子类就比较难选择了.所以java和C#不支持类的多继承2,允许具 ...

  6. How Many Answers Are Wrong(带权并查集)

    How Many Answers Are Wrong http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS ( ...

  7. MATLAB安装libsvm无法使用解决办法(转)

    buaasuozi  这是原作者: 安装libsvm 不成功有可能是你的MATLAB版本或者是编译文件版本的问题,但是不要急着换其他版本....说不定就有别的解决办法呢 首先感谢Lin教授及其实验室提 ...

  8. swift中UITextView的使用

    https://blog.csdn.net/potato512/article/details/52692604

  9. html5之history对象理解

    history对象之pushState,replaceState浏览器有一个history对象,用来保存浏览历史,用户可以通过点击浏览器的后退或前进按钮在历史记录中切换.之前对history的操作的A ...

  10. HBase Filter程序样例及Shell(图)

    ==过滤器执行流程== reset() : reset the filter state before filtering a new row. filterAllRemaining(): true ...