天天看点

HDU 5311 Hidden String

Problem Description

Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string  of length . He wants to find three nonoverlapping substrings , , 

  1. The concatenation of , , 

Input

There are multiple test cases. The first line of input contains an integer  , indicating the number of test cases. For each test case:

There's a line containing a string  

Output

For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).

Sample Input

2

annivddfdersewwefary

nniversarya

Sample Output

YES

NO

#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const ll maxn = 205;
int T, n, m, p, q, flag, f[maxn];
char s[maxn], c[maxn] = "anniversary";

void dfs(int x, int y, int z)
{
    if (z <= 3 && !c[x]) { flag = 1; return; }
    if (z > 3 || !c[x] || !s[y]) return;    
    dfs(x, y + 1, z); 
    if (c[x]==s[y])
    {
        while (c[x] && s[y] && c[x] == s[y]) x++, y++;
        dfs(x, y, z + 1);
    }
}

int main()
{
    cin >> T;
    while (T--)
    {
        scanf("%s", s);
        flag = 0;
        dfs(0, 0, 0);
        if (flag) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}