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 2 Open Book——22
I dropped my head, letting my hair fall to conceal my face. 我低下了我的头,让我的头发垂下来隐藏我的脸. I was sure,though ...
- VMWare桥接、NAT和only-host三种模式
如果你想利用VMWare安装虚拟机,或想创建一个与网内其他机器相隔离的虚拟系统,进行特殊的调试工作.此时,对虚拟系统网络连接模式的选择就非常重要了.如果你选择的工作模式不正确,就无法实现上述目的,也就 ...
- wamp服务器
wamp2.5会出现的问题,是因为WampServer2.5内置的是PHP5.5,而PHP5.5 环境是基于VC11的编译脚本下生成的,所以需要安装Visual Studio 2012 VC 11 v ...
- 一个forward_list C++primer
#include<iostream> #include<forward_list> using namespace std; int main() { forward_list ...
- angular中的ng-bind-html指令和$sce服务
angular js的强大之处之一就是他的数据双向绑定这一牛B功能,我们会常常用到的两个东西就是ng-bind和针对form的ng-model.但在我们的项目当中会遇到这样的情况,后台返回的数据中带有 ...
- 简单Spring和mybatis整合配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- OC画笔CGContextRef
1.画线 CGContextRef context = UIGraphicsGetCurrentContext();//context相当于画布 CGContextSetStrokeColorWith ...
- java 集合中将元素倒序排列
方法一:实现Comparable接口排序package collsort.comparable; package com.cvicse.sort.comparable; public class Ca ...
- Ansible5:常用模块【转】
根据zs官方的分类,将模块按功能分类为:云模块.命令模块.数据库模块.文件模块.资产模块.消息模块.监控模块.网络模块.通知模块.包管理模块.源码控制模块.系统模块.单元模块.web设施模块.wind ...
- 上传下载文件, 同时部署在webapps下, 而不是项目下,防止重新部署tomcat, 上传文件消失
前端上传 <a href='javascript:upload("+data[i].id+")' title='Upload Report'> <img src= ...