Codeforces805D. Minimum number of steps 2017-05-05 08:46 240人阅读 评论(0) 收藏
1 second
256 megabytes
standard input
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.
The first line contains the initial string consisting of letters 'a' and 'b'
only with length from 1 to 106.
Print the minimum number of steps modulo 109 + 7.
ab
1
aab
3
The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa".
#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) 收藏的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 175人阅读 评论(0) 收藏
一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...
- ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 174人阅读 评论(0) 收藏
一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...
- 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 ...
随机推荐
- How to Pronounce the Word THEM
How to Pronounce the Word THEM Share Tweet Share Tagged With: THEM Reduction Study the THEM reductio ...
- 【343】MathJax、LaTex、Mathml 数学公式
参考:cnblog中添加数学公式支持 分类参考: 1. 基本功能 MathJax 我的LaTeX入门 MathJax basic tutorial and quick reference 分段函数:矩 ...
- git cherry-pick用法
场景: 如果你的应用已经发布了一个版本2.0, 代码分支叫release-2.0, 现在正在开发3.0, 代码的分支叫dev-3.0. 那么有一天产品说, 要把正在开发的某个特性提前上线, 也就是说要 ...
- 《Blue Flke》第一次作业:团队亮相
1.队名:Blue Flke 团队格言:决心是成功的力量,耐心是成功的保障. 2.团队成员组成: 201571030129/ 王胜海 (组长) 201571030126/ 妥志福 20157103 ...
- 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 ...
- linux分区之gpt(大于2T的分区)
1.文件系统限制: ext3块尺寸 最大文件尺寸 最大文件系统尺寸1KiB 16GiB 2TiB2KiB 256GiB 8TiB4KiB 2TiB 16TiB8KiB 16TiB 32 ...
- [leetcode]269. Alien Dictionary外星字典
There is a new alien language which uses the latin alphabet. However, the order among letters are un ...
- [leetcode]299. Bulls and Cows公牛和母牛
You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...
- 版本号比较函数-js
面试前,让做的一个版本号比较函数. <script type="text/javascript"> var v1=prompt("请输入第一个版本号" ...
- python性能测试大致计划
hi guy: 如果注意到创建时间,那就对了.这份文章,是我学习Python一个月以后动手写的. 写下这份计划以后,只完成了第一步,其中磕磕绊绊编写代码的过程,很大一部分时间是完全用txt写的 ...