1093. Count PAT's (25)

时间限制
120 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CAO, Peng

The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.

Now given any string, you are supposed to tell the number of PAT's contained in the string.

Input Specification:

Each input file contains one test case. For each case, there is only one line giving a string of no more than 105 characters containing only P, A, or T.

Output Specification:

For each test case, print in one line the number of PAT's contained in the string. Since the result may be a huge number, you only have to output the result moded by 1000000007.

Sample Input:

APPAPT

Sample Output:

2

思路

试了下直接暴搜,果然最后几个测试点超时,看来还是得用dp。
这道题DP的思路就是用两个int数组P[n],T[n]保存第i个字符的左边字母'P'的个数P[i]和右边字母'T'的个数T[i],当遍历到的字符是'A'时,那么以这个A为基础的"PAT"字符串个数就是它左侧P字母个数乘以右侧T字母个数。即P[i]*T[i]
代码
#include<iostream>
#include<vector>
using namespace std;
int main()
{
string s;
while(cin >> s)
{
vector<int> P(,);
vector<int> T(,);
for(int i = ,j = s.size() - ;i < s.size() && j >= ;i++,j--)
{
if(s[i - ] == 'P')
{
P[i]++;
}
if(s[j + ] == 'T')
{
T[j]++;
}
P[i] += P[i - ];
T[j] += T[j + ];
} int sum = ;
for(int i = ;i < s.size();i++)
{
if(s[i] == 'A')
{
sum += P[i] * T[i];
sum %= ;
} }
cout << sum << endl;
}
}

PAT1093: Count PAT's的更多相关文章

  1. pat1093. Count PAT's (25)

    1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng The strin ...

  2. PAT 1093 Count PAT's[比较]

    1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...

  3. PAT甲级——1093 Count PAT's (逻辑类型的题目)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分)   ...

  4. PAT_A1093#Count PAT's

    Source: PAT A1093 Count PAT's (25 分) Description: The string APPAPT contains two PAT's as substrings ...

  5. 1093. Count PAT's (25)

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  6. 1093. Count PAT's

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  7. 1093. Count PAT’s (25)-统计字符串中PAT出现的个数

    如题,统计PAT出现的个数,注意PAT不一定要相邻,看题目给的例子就知道了. num1代表目前为止P出现的个数,num12代表目前为止PA出现的个数,num123代表目前为止PAT出现的个数. 遇到P ...

  8. 1093 Count PAT's(25 分)

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  9. PAT (Advanced Level) Practise - 1093. Count PAT's (25)

    http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as substrings ...

随机推荐

  1. tomcat整合apache

    历时4个多小时,终于把tomcat与apache整合起来了. 中间出了各种各样的问题,现记录一下,也希望能对后来者有点帮助. 背景 apache与tomcat的区别联系大家都知道: tomcat能处理 ...

  2. 网站开发进阶(二十四)HTML颜色代码表

    HTML颜色代码表 设置背景色:style='background-color:red' 设置字体颜色:style='color:red' 生活在于学习,知识在于积累.

  3. MT6575 3G切换2G

    因为了节省成本,需要从现在的3G方案切换置2G方案,做的修改,做个笔记. 一: 将MTK给过来的补丁编译出如下文件. 二:在mediatek/custom/common/modem/  路径下增加一个 ...

  4. R12.2. Start and Stop Procedure

    R12.2. Start and Stop Procedure   Leave a comment Individual Components:  Application(Middle Tier) $ ...

  5. Hibernate统计表中的条数

     /** * 判断积分日志表中是否有某个用户的注册日志 */@Transactional(propagation = Propagation.REQUIRED)public boolean isE ...

  6. Orientation Auto Rotation旋转屏幕crash问题(Unity3D开发之十四)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/44133127 ...

  7. MTK Android software Tools工具的说明

    MTK发布的Android software Tools工具包,里面包含了很多的MTK工具,如下是简要说明及学习文档 MTK Android software Tools工具的说明如下: 工具 说明 ...

  8. Linux - info

    基本上,info与man的用途其实差不多,都是用来查询命令的用法或者是文件的格式.但是与man page一口气输出一堆信息不同的是,info page则是将文件数据拆成一个一个的段落,每个段落用自己的 ...

  9. 【OpenCV学习】Kmean均值聚类对图片进行减色处理

            #include <cv.h> #include <highgui.h> #include <iostream> #define MAX_CLUST ...

  10. Java线程专栏文章汇总

        转载自 http://blog.csdn.net/ghsau/article/details/17609747 JDK5.0之前传统线程        Java线程(一):线程安全与不安全 J ...