【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 curious guy, so he wants to find the number of strictly increasing sequences p1,p2,…,pkp1,p2,…,pk, such that:
- For each ii (1≤i≤k1≤i≤k), spi=spi= 'a'.
- For each ii (1≤i<k1≤i<k), there is such jj that pi<j<pi+1pi<j<pi+1 and sj=sj= 'b'.
The Nut is upset because he doesn't know how to find the number. Help him.
This number should be calculated modulo 109+7109+7.
Input
The first line contains the string ss (1≤|s|≤1051≤|s|≤105) consisting of lowercase Latin letters.
Output
In a single line print the answer to the problem — the number of such sequences p1,p2,…,pkp1,p2,…,pk modulo 109+7109+7.
Examples
Input
abbaa
Output
5
Input
baaaa
Output
4
Input
agaa
Output
3
Note
In the first example, there are 55 possible sequences. [1][1], [4][4], [5][5], [1,4][1,4], [1,5][1,5].
In the second example, there are 44 possible sequences. [2][2], [3][3], [4][4], [5][5].
In the third example, there are 33 possible sequences. [1][1], [3][3], [4][4].
题目大意:
让你构造一个序列,有两个要求:1.全为‘a’字符。2.每两个a字符之间一定夹着至少一个b字符,求能构造出多少个这样的序列
解题报告:
扫一遍遇到a就记录,遇到b就终止并开始计数 最后输出答案,就行了
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
const ll mod = 1e9+7;
char s[MAX];
int main()
{scanf("%s", s + 1);int len = strlen(s + 1);ll ans = 1;for(int i = 1; i<=len; i++){ll cnt = 0;int cur = i;while(cur <= len){if(s[cur] == 'a') cnt++,cur++;else if(s[cur] == 'b') break;else cur++;}i = cur;ans = ans*(cnt+1) % mod;}ans--;printf("%lld\n", ans);return 0;}
【CodeForces - 1084C】The Fair Nut and String(思维,组合数学)相关推荐
- C - The Fair Nut and String
C - The Fair Nut and String CodeForces - 1084C 给出一个序列,求符合规则的序列有多少个,规则有两种,一种是只含a,一种是两个a之间夹着b. 对于每一个a有 ...
- 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 题解
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 数学
题目 The Fair Nut lives in n story house. ai people live on the i-th floor of the house. Every person ...
- 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 1084A The Fair Nut and Elevator
题意: 电梯要停在x层,每天早上要从x层去a层接人送到1层再回到x层的等待,每天晚上要从x层下到1层接人送到a层,再回到x层(对每层的乘客都是如此),电梯每走一层耗电1,问电梯停在那一层,每天的耗电最 ...
- Codeforces 1084A. The Fair Nut and Elevator
枚举电梯最开始停的位置,需要注意的是底层是1层不是0层. 判断x和i的位置关系,如果x在下面,那么上班的时候需要先上去,回家的时候同理 #include<bits/stdc++.h> us ...
- 【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 ...
- 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 题意: 在一棵树内找一条路径,使得从起点 ...
最新文章
- ​阿里达摩院金榕:从技术到科学,中国 AI 将何去何从?
- uniapp中easycom组件的封装
- LeetCode 编程 二
- Boost:gzip解压缩器
- 2021牛客多校1 - Hash Function(思维+FFT)
- 前端学习(582):实现观看和调试dom节点
- Mac下Apache使用
- recovery模式下支持ADB连接和串口操作
- 你真的了解Python吗?这篇文章可以让你了解90%,赶紧收藏!
- 中国塑料汽车外饰件市场趋势报告、技术动态创新及市场预测
- 进销存excel_Excel仓库进销存管理系统,全函数库存,查询汇总自动生成超简单...
- 路由在电话网和计算机网中的区别,计算机猫和路由器之间有什么区别
- windows系统IIS服务安装
- torch常用基础函数
- 怎样制作一个漂亮的艺术二维码?
- 怎么定位html的坐标,css怎么定位图片的位置?
- 6、指正的定义、内存、使用、指针常量、常量指针
- 只用div+CSS做淘宝手机端首页
- Spring—xml和注解
- OTSU算法的原理介绍及C++和Python实现
热门文章
- [Bugku][Web][CTF] 30-33 write up
- [Leetcode][第79题][JAVA][单词搜索][DFS][回溯]
- [Leetcode][第201题][JAVA][数字范围按位与][位运算][Brian Kernighan]
- [Java]中[this][super]用法总结
- 文件共享服务器地址格式,文件共享服务器配置
- centos6 5从命令行进入图形界面
- eclipse xml文件报错_Maven教程6: Maven与Eclipse整合
- 语言求圆周率近似值改错_新证明解决了如何求无理数的近似值
- php编译称opcode文件,PHP源码保护和性能加速
- landscape 1