codeforce1194C——From S To T——(子序列)

链接:https://codeforces.com/contest/1194/problem/C

题目大意:给你三个字符串s,p,t,问你能否在s串中的任何位置加入p串中的任何字符,从而使s串变成t串?

很简单,用序列自动机判断s是否为t的子序列,如果不是那就不可能变成t,如果是,判断t字符串中的每个字符是否在s或p中有就可以了。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

const int maxn=120;
char s[maxn],t[maxn],p[maxn];
int dp[maxn][30];//ађСаздЖЏЛњ
int now[maxn];
int num[3][30];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        cin>>s>>t>>p;
        memset(now,-1,sizeof(now));
        for(int i=strlen(t)-1;i>=0;i--){
            for(int j=0;j<26;j++){
                dp[i][j]=now[j];
            }
            now[t[i]-'a']=i;
        }
        //判断s是否为t的子序列
        int l=now[s[0]-'a'];
        if(l==-1){
            puts("NO");
            continue;
        }
        bool flag=true;
        for(int i=1;i

 

你可能感兴趣的:(字符串)