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> ...
随机推荐
- Linux Shell 小脚本经典收藏
原文:http://www.cnblogs.com/Javame/p/3867686.html 1.在两个文件中找出相同的号码 diff -y xx.txt oo.txt | egrep -v &qu ...
- python datetime时间差
import datetime import time d1 = datetime.datetime(2005, 2, 16) d2 = datetime.datetime(2004, 12, 31) ...
- vertor容器
头文件#include<vector> 1.创建vector对象 1.不指定容器大小 vector <int> v; 2.指定容器大小 vector <double&g ...
- PHP中字符串转换为数值 可能会遇到的坑
今天看到一个老外最喜欢的一段代码 <?php $string = 'zero'; $zero = 0; echo ($string == $zero) ? 'Why? Just why?!' : ...
- 纯CSS做的一个Silder
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 常用的opengl函数(三)
glBlendFunc 定义像素算法. void WINAPI glBlendFunc(GLenum sfactor,GLenum dfactor); 参数编辑 sfactor 指定红绿蓝和 al ...
- PHP商品倒计时 php实现当前用户在线人数
//PHP商品倒计时 date_default_timezone_set("Asia/shanghai");//地区 //配置每天的活动时间段 $starttimestr = &q ...
- 在DLL中导出另一静态库中的函数
开发环境: win7_x64.VS2013 应用场景: 动态库A依赖动态库B,而动态库B又使用了静态库C:有些情况下,我们需要将C从B里面导出,然后提供给A使用. 正文: Step1: 1.新建测试静 ...
- 单元测试、自动化测试、接口测试过程中的Excel数据驱动(java实现)
import java.io.FileInputStream;import java.io.InputStream;import java.util.HashMap;import java.util. ...
- 内存管理 & 内存优化技巧 浅析
内存管理 浅析 下列行为都会增加一个app的内存占用: 1.创建一个OC对象: 2.定义一个变量: 3.调用一个函数或者方法. 如果app占用内存过大,系统可能会强制关闭app,造成闪退现象,影响用户 ...