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改为bba,问需要变换多少次才能让字符串中没有ab
由题可知,ab判断两种情况: 1.ab前面有a时的变化, 2.ab后面有b时的变化;
具体解析放在代码中解释
 
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
char str[];
int main(){
int n,total,a;
scanf("%s",str);
total = a = ;
int len = strlen(str);
for(int i = ;i < len;i++){
if(str[i] == 'a'){ //由于只有a,b两个字母,只需判断是否为a
a = ( * a + ) % mod; //由于数据太大,只能一步一步取模,若将b前面的a个数加起来用2^n-1公式求值,数字会由于太大,变成负数
}else{
total = (total + a) % mod; //公式可自行推演,多推一下,很容易得出
}
}
printf("%d\n",total);
return ;
}

Codeforces Round #411 div 2 D. Minimum number of steps的更多相关文章

  1. 【推导】Codeforces Round #411 (Div. 1) B. Minimum number of steps

    最后肯定是bbbb...aaaa...这样. 你每进行一系列替换操作,相当于把一个a移动到右侧. 会增加一些b的数量……然后你统计一下就行.式子很简单. 喵喵喵,我分段统计的,用了等比数列……感觉智障 ...

  2. Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)

    A. Fake NP time limit per test:1 second memory limit per test:256 megabytes input:standard input out ...

  3. Codeforces Round #411 (Div. 2)

    来自FallDream的博客,未经允许,请勿转载,谢谢. 由于人傻又菜 所以这次又滚去div2了  一堆结论题真的可怕 看见E题不是很有思路   然后就去大力搞F题  T了最后一个点 真的绝望   但 ...

  4. Codeforces Round #411 (Div. 2) 【ABCDE】

    A. Fake NP 题意:给你l,r,让你输出[l,r]里面除1以外的,出现因子数量最多的那个数. 题解:如果l==r输出l,否则都输出2 #include<bits/stdc++.h> ...

  5. Codeforces Round #411 (Div. 2) A-F

    比赛时候切了A-E,fst了A Standings第一页只有三个人挂了A题,而我就是其中之一,真™开心啊蛤蛤蛤 A. Fake NP time limit per test 1 second memo ...

  6. Codeforces Round 411 Div.2 题解

    A Fake NP standard input/output s, MB Submit Add to favourites x3673 B -palindrome standard input/ou ...

  7. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  8. Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #411 (Div. 2) C. Find Amir

    C. Find Amir time limit per test   1 second memory limit per test   256 megabytes   A few years ago ...

随机推荐

  1. click事件和mousedown、mouseup事件

    点击select标签元素的时候,会弹出下拉.然而当option中没有元素时,就不希望弹出下拉(比如在某些浏览器中,点击select会默认出一个罩层效果,而此时没有数据选择的话,弹出比较不友好). 首先 ...

  2. ASP.NET Core 使用外部登陆提供程序登陆的流程,以及身份认证的流程 (转载)

    阅读目录 在Asp.Net Core 中使用外部登陆(google.微博...) 中间件管道 The Authentication Middleware The Challenge 与认证中间件进行交 ...

  3. 初始化应用程序数据ng-init指令

    ng-init指令初始化应用程序数据. 如果我们想给文本框一个初化的值: <div ng-app="" ng-init="Name='Leo'"> ...

  4. [Oracle]OWI学习笔记--001

    [Oracle]OWI学习笔记--001 在 OWI 的概念里面,最为重要的是 等待事件 和 等待时间. 等待事件发生时,需要通过 P1,P2,P3 查看具体的资源. 可以通过 v$session_w ...

  5. bitcoin 源码解析 - 交易 Transaction(二) - 原理篇

    这篇文章我断断续续写了呃···· 应该快三个星期了? 所以前后的风格可能差别相当大.真是十分的怠惰啊··· 最近实在是不够努力.用python重写bitcoin的项目也卡在网络编程部分(这方面真是我的 ...

  6. java 基础01

    标识符:字母,下划线和美元符号,数字组成大小写敏感,无长度限制 关键字: 数据类型

  7. PowerBI开发 第十五篇:DAX 表达式(时间+过滤+关系)

    DAX表达式中包含时间关系(Time Intelligence)相关的函数,用于对日期维度进行累加.同比和环比等分析.PowerBI能够创建关系,通过过滤器来对影响计算的上下文. 一,时间关系 DAX ...

  8. Node.js系列-express(下)

    前言 距上次更新博客又两个月多了,这两个月内除了上班时间忙公司的项目外,下班后也没有闲着,做了点外包,有小程序的,管理端的项目.也可能那段时间做的外包项目也都比较急,所以晚上都搞到一点左右睡,严重的压 ...

  9. 分布式监控系统Zabbix-添加windows监控主机

    大多数情况下,线上服务器都是linux系统,但是偶尔也会有些windows机器.下面简单介绍下zabbix添加windows监控机的操作:1)下载windows的zabbix_agent下载地址:ht ...

  10. 结构体内嵌比较函数bool operator < (const node &x) const {}

    直接看别人的链接 [http://www.cnblogs.com/ZERO-/p/9347296.html]