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 ...
随机推荐
- Scala语言学习笔记(2)
表达式,值,变量,代码块,函数,方法 // 表达式 1 + 1 println(1 + 1) // 2 // 值(values)使用 val 关键字声明,带初值时类型可省略. val x = 1 + ...
- Haskell语言学习笔记(62)Divisible
Divisible class Contravariant f => Divisible f where divide :: (a -> (b, c)) -> f b -> f ...
- Windows驱动手动卸载与安装
彻底卸载的流程 1.删除C:\windows\inf\oem.inf路径下的所有oem文件 2.删除c:\windows\system32\drivers路径下对应的sys文件 3.(重要) 第一步: ...
- Electron Browser加载iframe(webview src属性)
browser或者webcontents 的高度与宽度比例对webview中src的页面结构也是有一定影响的
- SpringMVC中在web.xml中添加中文过滤器的写法
<filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>or ...
- chrome input去除黄色背景色
input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset; border: 1px solid #CCC!impo ...
- Java按值传递、按引用传递
一般我们会说Java基本类型采用值传递,对象以及数组采用引用传递.但事实上这只是表面上的现象.实质上,Java都是按值传递引用.(Java中“引用”的概念相当于C++中的指针,可以不断改变值) 一,对 ...
- phpStudy1——PHP文件获取html提交的参数
示例代码: submit.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- c++中Socket编程(入门)
转载 :http://www.cnblogs.com/L-hq815/archive/2012/07/09/2583043.html 但该作者也是转载,国外网站翻译之作 本人在学习Socket编程时, ...
- python之socket运用之传输大文件
socket建议最大的传输单元是8192个字符,但是如果超过8192就会出现问题,我们可以用下面的方法处理 客户端代码 import subprocess import socket ip_bind ...