大意: 给定字符串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. notepad++正则表达式删除所有行某字符开始之前或者之后所有字符

    删除S 之后的所有字符用:s.*$ 删除S 之前的所有字符用:^.*s

  2. built-in SpecularType of Unity

    [built-in SpecularType of Unity] 1.声明变量. 注意并没有在Shader中声明_SpecColor,因为Lighting.cginc中已经帮我们声明. 2.声明使用B ...

  3. CG中的类型

    [Matrix] 通常像下面这样定义Matrix: int1x1 iMatrix; // integer matrix with 1 row, 1 column int4x1 iMatrix; // ...

  4. UIPanel

    [UIPanel] UIPanel is a component that collects and manages all widgets underneath it. UIPanel is res ...

  5. 69. Sqrt(x) (Divide-and-Conquer)

    Implement int sqrt(int x). Compute and return the square root of x. 注意: 计算平方的时候可能会溢出,所以mid要定义为long 另 ...

  6. 通过args数组获取数据

    ----------siwuxie095                     通过 main 方法的 args数组 可以从控制台获取一组字符串数据     如:     package com.s ...

  7. ssh的发展历程与基本原理

    一.ssh是什么 SSH(Secure Shell)是一个提供数据通信安全.远程登录.远程指令执行等功能的安全网络协议,最初提出目的是替代非安全的Telnet.rsh.rexec等远程Shell协议. ...

  8. Python OCR提取普通数字图形验证中的数字

    截取图形验证码: # -*- coding: UTF-8 -*- ''' Created on 2016年7月4日 @author: xuxianglin ''' import os import t ...

  9. Ubuntu下安装配置ScrumWorks

    1) 安装JDK6 Ubuntu默认的是OpenJDK,而ScrumWorks不支持使用OpenJDK哦,一次必须装个Oracle的JDK6   2) 下载安装Mysql5 http://dev.my ...

  10. [GO]json解析到结构体

    package main import ( "encoding/json" "fmt" ) type IT struct { Company string `j ...