大意: 给定字符串S, 要求维护三个串, 支持在每个串末尾添加或删除字符, 询问S是否能找到三个不相交的子序列等于三个串.

暴力DP, 若不考虑动态维护的话, 可以直接$O(len^3)$处理出最少需要S中前多少位能匹配.

考虑添加删除的话, DP刷表, $O(len^2q)$

#include <iostream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e5+10, M = 300;
int n, q;
char s[N], a[4][M];
int dp[M][M][M], nxt[N][27], len[4];
void upd(int x) {
REP(i,x==1?len[1]:0,len[1]) {
REP(j,x==2?len[2]:0,len[2]) {
REP(k,x==3?len[3]:0,len[3]) {
int &r = dp[i][j][k] = n+2;
if (i&&dp[i-1][j][k]+1<=n) r=min(r,nxt[dp[i-1][j][k]+1][a[1][i]-'a']);
if (j&&dp[i][j-1][k]+1<=n) r=min(r,nxt[dp[i][j-1][k]+1][a[2][j]-'a']);
if (k&&dp[i][j][k-1]+1<=n) r=min(r,nxt[dp[i][j][k-1]+1][a[3][k]-'a']);
}
}
}
} int main() {
scanf("%d%d%s", &n, &q, s+1);
REP(i,'a','z') {
nxt[n+1][i-'a']=n+2;
PER(j,1,n) {
if (s[j]==i) nxt[j][i-'a']=j;
else nxt[j][i-'a']=nxt[j+1][i-'a'];
}
}
REP(i,1,q) {
char op, c;
int x;
scanf(" %c%d", &op, &x);
if (op=='+') {
scanf(" %c", &c);
a[x][++len[x]]=c;
upd(x);
}
else --len[x];
puts(dp[len[1]][len[2]][len[3]]<=n?"YES":"NO");
}
}

Three Religions CodeForces - 1149B (字符串,dp)的更多相关文章

  1. Maximum Questions CodeForces - 900E (字符串,dp)

    大意:给定长$n$的字符串$s$, 只含'a','b','?', '?'可以替换为任意字符, 在给定长$t$的字符串, "ababab...", 求替换尽量少的'?', 使得$s$ ...

  2. Dreamoon and Strings CodeForces - 477C (字符串dp)

    大意: 给定字符串$s$, $p$, 对于$0\le x\le |s|$, 求$s$删除$x$个字符后, $p$在$s$中的最大出现次数. 显然答案是先递增后递减的, 那么问题就转化求最大出现次数为$ ...

  3. Erasing Substrings CodeForces - 938F (字符串dp)

    大意: 给定字符串$s$, 长度为$n$, 取$k=\lfloor log2(n)\rfloor$, 第$i$次操作删除一个长度为$2^{i-1}$的子串, 求一种方案使得, $k$次操作后$s$的字 ...

  4. Codeforces 176B (线性DP+字符串)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成 ...

  5. Codeforces 1150D(字符串dp)

    反思 三维的dp压根没看出来,看题解以后思路又很直观,找几道字符串dp练练才行 序列自动机和优化一维略 /* __ __ * ____| |_____| |____ * | | * | __ | * ...

  6. 【BZOJ 2121】 (字符串DP,区间DP)

    2121: 字符串游戏 Description BX正在进行一个字符串游戏,他手上有一个字符串L,以及其他一些字符串的集合S,然后他可以进行以下操作:对于一个在集合S中的字符串p,如果p在L中出现,B ...

  7. AtCoder Regular Contest 081 E - Don't Be a Subsequence(字符串DP)

    引用自:onion_cyc 字符串DP一直不是强项...以后没思路的题就想DP和网络流23333333 f[i]表示从i开始的后缀非子序列的最短长度  pos[i][j]表示从i开始的j字符最早出现位 ...

  8. NOIP2015Day2T2子串(字符串dp)

    又被“if(a=b)”坑了QAQ...写C++还是得开Warning,这么久了pascal还没改过来咋回事啊QWQ 题目大意就不说了OWO 网上的题解都不怎么看得懂啊...好像写得都很乱?还是我太sb ...

  9. codeforces#1183H. Subsequences(字符串dp)

    题目链接: http://codeforces.com/contest/1183/problem/H 题意: 给出一个长度为$n$的字符串,得到$k$个子串,子串$s$的花费是$n-|s|$ 计算最小 ...

随机推荐

  1. Spring事务管理API

  2. springboot 跳过单元测试

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-suref ...

  3. std::mutex 引起的 C2280 尝试引用已删除的函数

    起因是把之前写的类中的 mutex 使用了(之前注释掉了没用到这个变量); 或者说添加了一个 mutex 变量, 然后 这个类有嵌套在了 其类的 map 中使用, 然后 编译 就报错 ` C2280 ...

  4. Phong Shading

    [Phong Shading] The most serious problem with Gouraud shading occurs when specular highlights are fo ...

  5. Robocopy和xxcopy全掌握

    Windows提供的复制操作功能实在是太过简陋,可定制性又不强,在复制.移动.备份文件夹的时候,总要循环往复做多次操作.现在我们就向你介绍两款强力复制备份软件:Robocopy和XXCOPY,具体功能 ...

  6. 《Head First 设计模式》观后感——专业并不一定是深奥和枯燥

    <Head First 设计模式>观后感——专业并不一定是深奥和枯燥 说起设计模式,我想做程序的朋友都不会感到陌生,这就像是软件里的缩写一样,可以快速的表达一系列的意思. 但是纵观市面上的 ...

  7. 636. Exclusive Time of Functions 进程的执行时间

    [抄题]: Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU ...

  8. windows 查看端口被占用进程

    查看占用63243是谁 C:\Users\Administrator>netstat -aon|findstr "63243" TCP 172.27.33.11:63243 ...

  9. 修改字符集AL32UTF8修改为ZHS16GBK详解

    登陆sqlplus,在命令行输入 sqlplus sys/sys as sysdba;//登陆sqlplus SQL>SHUTDOWN IMMEDIATE; SQL>STARTUP MOU ...

  10. 40 Questions to test your skill in Python for Data Science

    Comes from: https://www.analyticsvidhya.com/blog/2017/05/questions-python-for-data-science/ Python i ...