C - The Fair Nut and String
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相关推荐
- 【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 ...
- 【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 ...
- 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 ...
- Codeforces 1084A - The Fair Nut and Elevator
Codeforces 1084A - The Fair Nut and Elevator 题解链接 https://lucien.ink 题目链接 https://codeforces.com/con ...
- 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 ...
- 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 题意: 在一棵树内找一条路径,使得从起点 ...
- CF1083A The Fair Nut and the Best Path
CF1083A The Fair Nut and the Best Path 先把边权搞成点权(其实也可以不用),那么就是询问树上路径的最大权值. 任意时刻权值非负的限制可以不用管,因为若走路径 \( ...
- 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 ...
- codeforces-1084AThe Fair Nut and Elevator-题解
题目大意: Nut在n层的房子里,ai人住在房子的第i-th层,每个人每天使用电梯两次:从他/她住的楼层到一楼,晚上回家时从一楼到他/她住的楼层. 不使用的电梯将停留在X层,(但是X还没有被选择).当 ...
最新文章
- 《c语言从入门到精通》看书笔记——第14章 文件
- java后台工具类-通过交易码获得方法名
- 二分法查找(C/C++)
- 推荐一个最近开源的Matting工具箱
- Openssl s_server命令
- itextpdf添加表格元素_基操勿6第四期:PPT表格美化
- spring配置数据源错误记录
- 【Luogu2394】yyy loves Chemistry I(浮点数精度)
- python有什么内容_python的类(简介,没什么内容)
- Apache环境利用.htaccess文件设置域名301跳转(不带www跳转到带www)
- linux内核C -- 第07课:地址对齐那些事儿
- 使用plsql管理oracle数据库连接,使用PLSQL连接远程oracle数据库
- plc仿真实训软件_博途STEP7仿真软件与真实PLC的区别
- qt 字体旋转90_如何识别图片和视频上文字的字体
- 深入理解JAVA中的JNDI注入
- 纯色图制作APP代码
- 软件性能测试pdf,软件性能测试报告模板.pdf
- 数据库版本管理框架-Flyway
- 逻辑运算符 异或是什么意思 异或运算
- 世界杯的征程,一千个夺冠的理由