PAT (Advanced Level) 1093. Count PAT's (25)
预处理每个位置之前有多少个P,每个位置之后有多少个T。
对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数。
#include<cstdio>
#include<cstring> long long MOD=1e9+;
const int maxn=1e5+; long long dp1[maxn],dp2[maxn];
char s[maxn]; int main()
{
scanf("%s",s);
memset(dp1,,sizeof dp1);
if(s[]=='P') dp1[]=;
for(int i=;s[i];i++)
{
dp1[i]=dp1[i-];
if(s[i]=='P') dp1[i]++;
}
memset(dp2,,sizeof dp2);
int len=strlen(s);
if(s[len-]=='T') dp2[len-]=;
for(int i=len-;i>=;i--)
{
dp2[i]=dp2[i+];
if(s[i]=='T') dp2[i]++;
}
long long ans=;
for(int i=;s[i];i++)
{
if(s[i]=='A')
ans=(ans+dp1[i-]*dp2[i+])%MOD;
}
printf("%lld\n",ans);
return ;
}
PAT (Advanced Level) 1093. Count PAT's (25)的更多相关文章
- 【PAT甲级】1093 Count PAT's (25 分)
题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1110. Complete Binary Tree (25)
判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...
- PAT (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT (Advanced Level) 1074. Reversing Linked List (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1062. Talent and Virtue (25)
简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...
- PAT (Advanced Level) 1060. Are They Equal (25)
模拟题.坑点较多. #include<iostream> #include<cstring> #include<cmath> #include<algorit ...
- PAT (Advanced Level) 1056. Mice and Rice (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- PAT (Advanced Level) 1052. Linked List Sorting (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- Chapter 1 First Sight——30
The girl sitting there giggled. I'd noticed that his eyes were black — coal black. 那个坐在那里的女孩笑着.我注意到她 ...
- -Swift.h not find
亲测成功. 随便新建一个swift文件,xcode问是否生成xxx-Bridging-Header.h文件,点YES.再编译,问题解决. By default, the generated heade ...
- 01_change_schema.sql
set echo on feedback on spool ./log/01_change_schema.log -- -- schema change to v_idocdata_un -- -- ...
- php秒杀
我们知道数据库处理sql是一条条处理的,假设购买商品的流程是这样的: sql1:查询商品库存 ? 1 2 3 4 5 if(库存数量 > 0) { //生成订单... sql2:库存-1 ...
- VS2010+PCL+openni配置
PCL中文论坛:http://www.pclcn.org/bbs/forum.php 1.安装 pcl 的完全安装包可以到: http://pointclouds.org/downloads/wind ...
- Android Camera(一)
最近老大交给了一个任务,说是要在本地视频端很够调节摄像头焦距. 碰到了一些问题: 1.手机支不支持摄像头变焦 2.系统自带摄像软件可以变焦,但是自己编写的程序不支持变焦, 这个问题网上也有很多童鞋碰到 ...
- VideoView的视频的全屏播放
import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.I ...
- hdu 3342 Legal or Not(拓扑排序)
Legal or Not Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total ...
- 转:通过ant来批量执行jmeter脚本,并生成报告(附: 生成报告时报“Content is not allowed in prolog”这个错误的解决方案)
最近在使用jmeter写脚本来进行测试,最终写了很多份脚本,然后,就在想,这么多脚本,我不可能一个一个的手动去点啊,有没有什么办法来批量运行Jmeter脚本呢? 这个时候,自然而然地想到了万能的ant ...
- InnoDB的数据页结构
页是InnoDB存储引擎管理数据库的最小磁盘单位.页类型为B-tree node的页,存放的即是表中行的实际数据了. InnoDB数据页由以下七个部分组成,如图所示: File Header(文件头) ...