预处理每个位置之前有多少个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. MFC单选按钮

    先为对话框加上2个radio button,分别是Radio1和Radio2. 问题1:如何让Radio1或者Radio2默认选上?如何知道哪个被选上了? 关键是选上,“默认”只要放在OnInitDi ...

  2. aspx中如何加入javascript

    Response.Write("<script>window.location ='aaa.aspx';</script>"); Response.Writ ...

  3. DOM操作-克隆元素

    代码: ———————————————————————————— <script type="text/javascript">            //克隆元素   ...

  4. 禁止 一些地区的ip用户访问 网站

    01 framework.php 中 获取请求的ip地址.保存为常量 define('IP', request::get_clientip()); 02 setting表中.属于system模块,保存 ...

  5. .Net 读取xml

    一.常规方法 1.知识介绍 //初始化一个xml对象 XmlDocument xml = new XmlDocument(); //加载xml文件 xml.Load("文件路径") ...

  6. 在Service服务中请求网络

    一.startservice方式启动 第一次startservice启动服务的时候,会走oncreate和onstart方法, 第二次startservice启动服务的时候,会走onstart方法, ...

  7. hibernate5 中的schemaExport

    hibernate5中的schemaExport与之前版本中的用法有所不同,具体用法如下: ServiceRegistry serviceRegistry = new StandardServiceR ...

  8. 华哥倒酒<区间标记,二分>

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; t ...

  9. 门面模式(Facade)解析

    门面模式使用一个门面类来包装一些复杂的类,对外提供一个简单的访问方法. 见如下代码: class CPU { public void startup() { System.out.println(&q ...

  10. 文本格式ANSI,Unicode等有什么区别

    首先DBCS是亚洲的字符集,包含了ANSI,ANSI也就是ASCII值为0-255之间的字符,当字符为ANSI时,存放于文件中占用的是一个字节.如果是非ANSI的呢,则占用两字节.用VB的ASC函数可 ...