1093. Count PAT's 发表于 2021-01-10 分类于 algorithm-practice , PTA 阅读次数: 本文字数: 128 阅读时长 ≈ 1 分钟#题意计算PAT字串个数#思路动态规划?增加一个PAT个数PA个数P个数P不变不变增加1A不变增加前面的P的个数不变T增加前面的PA字串的个数不变不变#代码1234567891011121314151617181920212223#include <iostream>using namespace std;typedef long long ll;int main(){ string s; cin >> s; int n = s.size(); ll p = 0, pa = 0, pat = 0; for (int i = 0; i < n; i++) { switch (s[i]) { case 'P': p++; break; case 'A': pa = (pa + p) % 1000000007; break; case 'T': pat = (pat + pa) % 1000000007; break; } } cout << pat % 1000000007 << endl; return 0;}