预处理每个位置之前有多少个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)的更多相关文章

  1. 【PAT甲级】1093 Count PAT's (25 分)

    题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...

  2. PAT (Advanced Level) 1113. Integer Set Partition (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  3. PAT (Advanced Level) 1110. Complete Binary Tree (25)

    判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...

  4. PAT (Advanced Level) 1094. The Largest Generation (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  5. PAT (Advanced Level) 1074. Reversing Linked List (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  6. PAT (Advanced Level) 1062. Talent and Virtue (25)

    简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...

  7. PAT (Advanced Level) 1060. Are They Equal (25)

    模拟题.坑点较多. #include<iostream> #include<cstring> #include<cmath> #include<algorit ...

  8. PAT (Advanced Level) 1056. Mice and Rice (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  9. PAT (Advanced Level) 1052. Linked List Sorting (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. html/css技巧总结

    .e-select .on{display:none} on为e-select的子元素,(之间有空格).e-select.on{display:block} 只有两种属性同时存在时才会起作用(之间无空 ...

  2. nefu 72 N!

    Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, ...

  3. SQL Server不能通过外部IP访问,解决方法

    SQL Server不能通过外部IP访问,解决方法   版本:SQL server 2008 express with tools   打开配置管理器,开启 TCP,右键属性设置TCP端口:   设置 ...

  4. SUPERVISOR进程管理器配置指南

    SUPERVISOR进程管理器配置指南1. supervisor简介1.1. 官网http://supervisord.org/ 1.2. 介绍Supervisor是一个进程控制系统. 它是一个C/S ...

  5. 萝卜德森的sublime笔记中文翻译版

    我已经使用subliem编辑器版本2接近2个月了,并且我在其中找到了一堆有用的技巧.我发觉应该写下这些技巧,为那些对此感兴趣的人们.我会尽力的详细描述,那些看起来像魔法一样的东西,因为很多非常“酷”的 ...

  6. linux c中select使用技巧

    1.select函数作为定时器使用    it_value.tv_sec = 0;    it_value.tv_usec = 100000:    select(1,NULL,NULL,NULL,& ...

  7. 报表Reporting S而vice是 错误的解决

    Reporting Services 错误 报表服务器无法打开与报表服务器数据库的连接.所有请求和处理都要求与数据库建立连接. (rsReportServerDatabaseUnavailable)获 ...

  8. c++之模板

    . 函数模板 普通函数 void Swap(int &, int &); 模板函数 template <typename T> void Swap(T &, T & ...

  9. MySQL SQL优化——分片搜索

    DELIMITER $$ DROP PROCEDURE IF EXISTS `test_release`.`Sp_JP_A_NotifyBegin`$$ CREATE DEFINER=`encysys ...

  10. nginx+php-fpm 的配置下,php的错误日志

    发现php 运行错误时,浏览器的网页上并没有输出php的错误日志.那php的错误日志在哪里呢? 发现在 /var/log/nginx/error.log文件中. 怎么样才能在浏览器的网页中输出php的 ...