C - The Fair Nut and String

CodeForces - 1084C

给出一个序列,求符合规则的序列有多少个,规则有两种,一种是只含a,一种是两个a之间夹着b。

对于每一个a有两种选择,一种是取,一种是不取,例如“aaa”,对应4种选择,a,aa,aaa,0/。为什么会有不取的选择,因为如果取这些a,那么下一波遇到一个a,就可以和这些形成规则2,如果不取,那么下一波遇到的a就代表着规则1。所以每次计数器清零后都应该归1,而不是归0;

#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#define ll long long
const int mod = 1e9 + 7;
using namespace std;int main()
{string str;ll ans = 0;cin >> str;int len = str.length();ans = 1;ll num = 1;for (int i = 0; i < len; i++) {if (str[i] == 'a') num++;else if (str[i] == 'b') {ans = ans * num % mod;num = 1;}}ans = ans * num % mod;ans -= 1;cout << ans << endl;}

C - The Fair Nut and String相关推荐

  1. 【CodeForces - 1084C】The Fair Nut and String(思维,组合数学)

    题干: The Fair Nut found a string ss. The string consists of lowercase Latin letters. The Nut is a cur ...

  2. 【CodeForces - 1084D】The Fair Nut and the Best Path (树形dp)

    题干: The Fair Nut is going to travel to the Tree Country, in which there are nn cities. Most of the l ...

  3. CodeForces 1084A The Fair Nut and Elevator 题解

    A. The Fair Nut and Elevator time limit per test : 1 second memory limit per test : 256 megabytes in ...

  4. Codeforces 1084A - The Fair Nut and Elevator

    Codeforces 1084A - The Fair Nut and Elevator 题解链接 https://lucien.ink 题目链接 https://codeforces.com/con ...

  5. CodeForces - 1084A The Fair Nut and Elevator 数学

    题目 The Fair Nut lives in n story house. ai people live on the i-th floor of the house. Every person ...

  6. CF 1083 A. The Fair Nut and the Best Path

    A. The Fair Nut and the Best Path https://codeforces.com/contest/1083/problem/A 题意: 在一棵树内找一条路径,使得从起点 ...

  7. CF1083A The Fair Nut and the Best Path

    CF1083A The Fair Nut and the Best Path 先把边权搞成点权(其实也可以不用),那么就是询问树上路径的最大权值. 任意时刻权值非负的限制可以不用管,因为若走路径 \( ...

  8. CodeForces 1084D The Fair Nut and the Best Path(树形dp)

    题目描述 The Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the l ...

  9. codeforces-1084AThe Fair Nut and Elevator-题解

    题目大意: Nut在n层的房子里,ai人住在房子的第i-th层,每个人每天使用电梯两次:从他/她住的楼层到一楼,晚上回家时从一楼到他/她住的楼层. 不使用的电梯将停留在X层,(但是X还没有被选择).当 ...

最新文章

  1. 《c语言从入门到精通》看书笔记——第14章 文件
  2. java后台工具类-通过交易码获得方法名
  3. 二分法查找(C/C++)
  4. 推荐一个最近开源的Matting工具箱
  5. Openssl s_server命令
  6. itextpdf添加表格元素_基操勿6第四期:PPT表格美化
  7. spring配置数据源错误记录
  8. 【Luogu2394】yyy loves Chemistry I(浮点数精度)
  9. python有什么内容_python的类(简介,没什么内容)
  10. Apache环境利用.htaccess文件设置域名301跳转(不带www跳转到带www)
  11. linux内核C -- 第07课:地址对齐那些事儿
  12. 使用plsql管理oracle数据库连接,使用PLSQL连接远程oracle数据库
  13. plc仿真实训软件_博途STEP7仿真软件与真实PLC的区别
  14. qt 字体旋转90_如何识别图片和视频上文字的字体
  15. 深入理解JAVA中的JNDI注入
  16. 纯色图制作APP代码
  17. 软件性能测试pdf,软件性能测试报告模板.pdf
  18. 数据库版本管理框架-Flyway
  19. 逻辑运算符 异或是什么意思 异或运算
  20. 世界杯的征程,一千个夺冠的理由

热门文章

  1. 开源的麦克纳姆轮全向移动机器人套件
  2. 模拟电话设置座机不能外呼,且呼入时呼叫转移到手机
  3. OkGo第三方框架的上传与下载+Glide图片加载器
  4. 五、python-地图可视化篇(黑马程序猿-python学习记录)
  5. Modulo (mathematics)
  6. 4路3G-SDI的两种拼接方式
  7. 怎么判断是程序存在问题还是软硬件系统存在问题
  8. 曙光1620-G20装Windows server 2008教程
  9. kafka之Consumer消费者基本概念
  10. 智慧医疗读书笔记(1-2)