1093 Count PAT‘s
这题出现在“活用递推”专题下面,所谓递推就是这一步的结果和上一步的结果有直接联系。对于本题来说,从左到右,记到当前位置,一共出现的P的个数,如果当前位置是P,则个数就是上一位的加1,否则等于上一位。
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bits/stdc++.h>
#include<stdlib.h>
#include<time.h>using namespace std;
typedef long long LL;const int maxn = 100010;
const int MOD = 1000000007;
const int INF = 1000000000;//INF:下确界
const LL SUP = (1LL<<63)-1;//SUP:上确界
const double eps = 1e-5;int main(){char str[maxn];int count_P[maxn];int count_T[maxn];scanf("%s",str);int len = strlen(str);//从头到尾,数Pif(str[0]=='P')count_P[0]=1;else count_P[0]=0;for(int i=1;i<len;i++){if(str[i]=='P')count_P[i]=count_P[i-1]+1;else count_P[i]=count_P[i-1];}//从尾到头,数Tif(str[len-1]=='T')count_T[len-1]=1;else count_T[len-1]=0;for(int i=len-2;i>=0;i--){if(str[i]=='T')count_T[i]=count_T[i+1]+1;else count_T[i]=count_T[i+1];}//对于下标在1~len-2上的A逐个记组成PAT的数量LL res = 0;for(int i=2;i<=len-1;i++){if(str[i]=='A')res += (LL)count_P[i]*count_T[i];}int count = res%(LL)MOD;printf("%d",count); return 0;
}
1093 Count PAT‘s相关推荐
- 【PAT (Advanced Level) Practice】1093 Count PAT‘s (25 分)
1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...
- PAT甲级1093 Count PAT‘s :[C++题解]DP、状态机模型dp
文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:统计子串"PAT"的数量. 状态机模型:本题需要的是PAT,需要选3个字母,对应三条边,需要4个状态. 下面以样例 ...
- 1093 Count PAT‘s (25 分)【难度: 一般 / 知识点: 前缀和 组合数】
https://pintia.cn/problem-sets/994805342720868352/problems/994805373582557184 PAT乙级的原题,这里不在赘述,就是前缀和, ...
- 【PAT甲级 排列组合】1093 Count PAT's (25 分) C++ 全部AC
题解 对于字符串中每个A而言,若其前面有m个P,后面有n个T,可以得到对于当前的A,能够组成m*n种情况的PAT. 因此找到A的位置,用A左边P的个数*A右边T的个数即可. 题解1:我的解法 C++ ...
- 【PAT】1093. Count PAT's (25)【模拟题】
题目描述 The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th ...
- PATA 1093 有几个PAT
题目: 1093 Count PAT's The string APPAPT contains two PAT's as substrings. The first one is formed by ...
- PAT甲级题目翻译+答案 AcWing(动态规划)
1007 Maximum Subsequence Sum (25 分) 题意 :注意最后输出的不是索引而是在那个索引的数 思路 :f为当前的假设开始指针,每一次累加到sum,如果sum大于res,就更 ...
- PAT (Advanced Level) Practice 题解代码 - II (1051-1100)
PAT PAT (Advanced Level) Practice - II(1051-1100) -------------------------------------------------- ...
- 刷PAT甲级的各题思路、细节以及遇到的问题记录
1001 A+B Format (20分) 因为一定会用到字符串,而string非常好用,但是用的时候一定要注意不能越界访问,否则会在运行时出现abort() has been called. 100 ...
最新文章
- 如何自动校正服务器时间,几个常用校正服务器时间
- python写接口自动化需要rsa加密_RSA加密,请问如何用Python实现该加密过程
- 20201010《近代数学》第1节课 笔记
- Android窗口管理服务WindowManagerService切换Activity窗口(App Transition)的过程分析
- QT| C/C++之win98扫雷外挂增强版
- windows 上的应用性能测试
- MapReduce实现词频统计
- 30秒的PHP代码片段(1)数组 - Array
- java day55【 Mybatis 连接池与事务深入 、 Mybatis 的动态 SQL 语句、 Mybatis 多表查询之一对多 、 Mybatis 多表查询之多对多】...
- ContextCapture(smart3D)10.20.下载安装教程
- html hr 垂直居中,常见的CSS水平垂直居中设置
- win10更改/修改c盘下的用户名/Users
- 用piranha配置LVS
- Spring基础学习(一)
- 数据分析——关于同比与环比,你真的了解吗?看看踩过的坑
- Spring cloud网关gateway代理websocket报Max frame length of 65536 has been exceeded
- vcf 文件拼接(snp、indel)
- Win11的两个实用技巧系列之没有声音如何解决、bat代码怎么写
- 从FASTA文件中批量提取指定序列【Python脚本】
- 非极大抑制(Non-Maximum Suppression)
热门文章
- Docker学习笔记_安装ActiveMQ
- leetcode381. Insert Delete GetRandom O(1) - Duplicates allowed
- Java基础知识回顾之六 ----- IO流
- 全网把Map中的hash()分析的最透彻的文章,别无二家。
- Spring-boot+Vue = Fame 写blog的一次小结
- 那些对混合云开发和应用程序环境的错误认识
- ASP.Net中的TreeView控件中对节点的上移和下移操作
- POJO、VO、PO、FormBean区别:
- MaxCompute studio与权限那些事儿
- Linux-find命令应用举例-按时间筛选和删除文件