1093 Count PAT's

1093 Count PAT‘s

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 10?5?? characters containing only PA, 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.

思路:对于每个A,记录它的前面有几个P,后面有几个T;然后对于每个A,PAT的组合有(前P)*(后T)种

 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4 #include <queue>
 5 using namespace std;
 6 const int maxn = 100005;
 7
 8 int main(){
 9     string s; cin >> s;
10     int pre[maxn], back[maxn];
11     fill(pre,pre+maxn,0); fill(back, back+maxn, 0);
12     int preP=0;
13     for(int i=0;i<s.length();i++){
14         pre[i] = preP;
15         if(s[i]==‘P‘) preP++;
16     }
17     int backT=0;
18     for(int i=s.length()-1;i>=0;i--){
19         back[i] = backT;
20         if(s[i]==‘T‘) backT++;
21     }
22     long long cnt;
23     for(int i=0;i<s.length();i++){
24         if(s[i]==‘A‘){
25             cnt += pre[i]*back[i];
26         }
27         if(cnt>1000000007) cnt%=1000000007;
28     }
29     printf("%lld\n",cnt);
30 }

1093 Count PAT's

原文地址:https://www.cnblogs.com/lokwongho/p/9940857.html

时间: 2024-10-12 12:14:22

1093 Count PAT's的相关文章

1093. Count PAT&#39;s (25)

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 numb

PAT (Advanced Level) 1093. Count PAT&#39;s (25)

预处理每个位置之前有多少个P,每个位置之后有多少个T. 对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数. #include<cstdio> #include<cstring> long long MOD=1e9+7; const int maxn=1e5+10; long long dp1[maxn],dp2[maxn]; char s[maxn]; int main() { scanf("%s",s); memset(dp1,0,sizeof d

1093. Count PAT&#39;s (25)想法题吧,算是排列组合吧

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 3r

1093. Count PAT&#39;s (25)【计数】——PAT (Advanced Level) Practise

题目信息 1093. Count PAT's (25) 时间限制120 ms 内存限制65536 kB 代码长度限制16000 B 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 c

PAT Advanced 1093 Count PAT&#39;s (25分)

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 numb

pat1093. Count PAT&#39;s (25)

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 3r

A1093. Count PAT&#39;s (25)

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 numb

PAT Advanced level 1093

1093 Count PAT's (25)(25 分) 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 a

PAT甲级题分类汇编——杂项

集合.散列.数学.算法,这几类的题目都比较少,放到一起讲. 题号 标题 分数 大意 类型 1063 Set Similarity 25 集合相似度 集合 1067 Sort with Swap(0, i) 25 通过与0号元素交换来排序 数学 1068 Find More Coins 30 子集和问题 算法 1070 Mooncake 25 背包问题 算法 1078 Hashing 25 散列 散列 1085 Perfect Sequence 25 符合约束的最大数列长度 集合 1092 To