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 3-Syllable Phrases
How To Pronounce 3-Syllable Phrases Share Tweet Share Tagged With: 3-Syllable Learn about the stress ...
- Haskell语言学习笔记(69)Yesod
Yesod Yesod 是一个使用 Haskell 语言的 Web 框架. 安装 Yesod 首先更新 Haskell Platform 到最新版 (Yesod 依赖的库非常多,版本不一致的话很容易安 ...
- Mysql count+if 函数结合使用
Mysql count+if 函数结合使用 果林椰子 关注 2017.05.18 13:48* 字数 508 阅读 148评论 0喜欢 1 涉及函数 count函数 mysql中count函数用于统计 ...
- Python递归的经典案例
目录 : 一.递归的简介 二.递归的经典应用 2.1 递归求阶乘 2.2 递归推斐波那契数列 2.3 二分法找有序列表指定值 2.4 递归解汉诺塔 前言: 当我们碰到诸如需要求阶乘或斐 ...
- distinct top執行順序
select distinct top 3 from table; 先distinct后top
- 使用JSON.parse()转化成json对象需要注意的地方
http://blog.csdn.net/u011277123/article/details/53055479 有三种方法: var str = '{"name":"小 ...
- poj1088(记忆化搜索入门题)
题目链接:http://poj.org/problem?id=1088 思路: 明显的记忆化搜索题,用dp[i][j]表示从(i,j)出发能滑的最远距离,用dfs搜索,若dp[x][y]>0即已 ...
- 利用python计算windows全盘文件md5值的脚本
import hashlib import os import time import configparser import uuid def test_file_md5(file_path): t ...
- 安装Oracle客户端寻找配置文件tnsnames.ora
# tnsnames.ora Network Configuration File: D:\app\Administrator\product\11.2.0\dbhome_1\network\admi ...
- php 使用PHPExcel 导出数据为Excel
<?php require_once 'PHPExcel/Classes/PHPExcel.php'; /** * 导出数据为Excel * @param array $fieldArr 标题数 ...