Codeforces Round #526 (Div. 2) C. The Fair Nut and String
C. The Fair Nut and String
题目链接:https://codeforces.com/contest/1084/problem/C
题意:
给出一个字符串,找出都为a的子序列(比如ai,aj,ak)满足以下条件的个数:
1.子序列的索引单增(i<j<k);
2.在原字符串中,若ai=aj=ak=a,那么满足i<=k1<j,j<=k2<k 并且 ak1=ak2=b。
通俗点说,就是找这样的子序列个数:要么单个a,要么每个a之间都至少有一个b。
题解:
我们考虑在字符串末尾增加一个”哨兵“,其值为b。然后用b对a进行分割,每一段a 的个数为ai。
最后统计结果:(a1+1)*(a2+1)*...*(ax+1)-1。这里减去1是因为至少没有什么都不选的情况。
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+,MOD = 1e9+;
char s[N];
ll a[N];
int main(){
scanf("%s",s);
int len=strlen(s);
s[len]='b';
int num=,cnt=;
for(int i=;i<=len;i++){
if(s[i]=='a') num++;
if(s[i]=='b'){
a[++cnt]=num;
num=;
}
}
ll ans = ;
for(int i=;i<=cnt;i++) ans=ans*(a[i]+)%MOD;
printf("%I64d",ans-);
return ;
}
Codeforces Round #526 (Div. 2) C. The Fair Nut and String的更多相关文章
- Codeforces Round #526 (Div. 2) E. The Fair Nut and Strings
E. The Fair Nut and Strings 题目链接:https://codeforces.com/contest/1084/problem/E 题意: 输入n,k,k代表一共有长度为n的 ...
- Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path
D. The Fair Nut and the Best Path 题目链接:https://codeforces.com/contest/1084/problem/D 题意: 给出一棵树,走不重复的 ...
- Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path 树上dp
D. The Fair Nut and the Best Path 题意:给出一张图 点有权值 边也要权值 从任意点出发到任意点结束 到每个点的时候都可以获得每个点的权值,而从边走的时候都要消耗改边的 ...
- Codeforces Round #526 (Div. 2) Solution
A. The Fair Nut and Elevator Solved. 签. #include <bits/stdc++.h> using namespace std; #define ...
- A. The Fair Nut and Elevator (Codeforces Round #526 (Div. 2))
A. The Fair Nut and Elevator 好笨啊QAQ. 暴力枚举的题,连分类都不用. 从电梯初始位置到第一层.人到第一层.间隔的层数,往返路程. #include <bits/ ...
- Codeforces Round #526 (Div. 2) A.B
A. The Fair Nut and Elevator 题目链接:https://codeforces.com/contest/1084/problem/A 题意: 一栋房子有n层楼,同时有个电梯( ...
- Codeforces Round #526 (Div. 1)
毕竟是上紫之后的第一场div1,还是太菜了啊,看来我要滚回去打div2了. A. The Fair Nut and the Best Path 这题本来是傻逼贪心dfs,结果我越写越麻烦,然后就只有1 ...
- Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)
A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [Codeforces Round #526 (Div. 2)]
https://codeforces.com/contest/1084 A题 数据量很小,枚举就行 #include<iostream> #include<cstdio> #i ...
随机推荐
- requests模块基础
requests模块 .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { bor ...
- Python3爬虫(五)解析库的使用之XPath
Infi-chu: http://www.cnblogs.com/Infi-chu/ XPath: 全称是 XML Path Language,XML路径语言,它是一门在XML文档中和HTML文档中查 ...
- Go语言中的HTTP
Go中的http使用 package main import ( "fmt" "net/http" "io/ioutil" "st ...
- (数据科学学习手札09)系统聚类算法Python与R的比较
上一篇笔者以自己编写代码的方式实现了重心法下的系统聚类(又称层次聚类)算法,通过与Scipy和R中各自自带的系统聚类方法进行比较,显然这些权威的快捷方法更为高效,那么本篇就系统地介绍一下Python与 ...
- 43-Identity MVC:UI
1-打开之前写的MvcCookieAuthSample项目, 在AccountController新加Register,Login方法 public class AccountController : ...
- docker windows container的一些注意点
1.在阿里云esc的ws2016里装docker只能使用windows container,因为官方也说了主机也是虚拟机所以不能开启Hyper-v. 2.默认使用nat模式运行network,该模式在 ...
- How to add a webpart to your website
I have download a webpart that can play media on the website from the internet.Then how to add ...
- 问题:docker pull 用户登陆tricky,Error response from daemon: unauthorized: incorrect username or password
问题描述: PS C:\WINDOWS\system32> docker pull rabbitmqUsing default tag: latest Please login prior to ...
- javaX邮件发送
/** * * * @param mailServerHost 邮件服务器 * @param mailServerPort 端口 * @param validate 是否需要身份验证 * @para ...
- [Linux] 服务器镜像定时备份解决方案 crontab+rsync+flock
两台服务器定时同步文件解决方案: 环境: 主机:192.168.1.1 镜像机:192.168.1.2 需要将主机内容备份至镜像机(假设用户都为root) 备份内容为 /export 目录下所有内容至 ...