Hidden String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 1677    Accepted Submission(s): 589

Problem Description
Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string
s
of length n.
He wants to find three nonoverlapping substrings s[l1..r1],
s[l2..r2],
s[l3..r3]
that:



1. 1≤l1≤r1<l2≤r2<l3≤r3≤n



2. The concatenation of s[l1..r1],
s[l2..r2],
s[l3..r3]
is "anniversary".
 
Input
There are multiple test cases. The first line of input contains an integer
T
(1≤T≤100),
indicating the number of test cases. For each test case:



There's a line containing a string s
(1≤|s|≤100)
consisting of lowercase English letters.
 
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
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5594 5593 5592 5591 5590

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str[1010],op[13]={"anniversary"};
int flog,l,L;
void dfs(int b1,int b2,int num)
{
int i;
if(b2>=11&&num<=3)
{
flog=1;
return ;
}
if(num>3)
return ;
if(b1>=l||flog)
return ;
for(i=b1;i<l;i++)
{
int x=i;
int y=b2;
while(str[x]==op[y]&&x<l&&y<11)
{
x++,y++;
}
dfs(x+1,y,num+1);
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
L=strlen(op);
memset(str,'\0',sizeof(str));
scanf("%s",str);
flog=0;
l=strlen(str);
dfs(0,0,0);
if(flog)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

hdoj--1034--Hidden String(dfs)的更多相关文章

  1. HDU 5311 Hidden String (暴力)

    题意:今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为n的字符串s. 他想要知道能否找到s的三个互不相交的子串s[l1..r1], s[l2..r2], s[l3..r3]满足下 ...

  2. 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现

    1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...

  3. 搜索——深度优先搜索(DFS)

    设想我们现在身处一个巨大的迷宫中,我们只能自己想办法走出去,下面是一种看上去很盲目但实际上会很有效的方法. 以当前所在位置为起点,沿着一条路向前走,当碰到岔道口时,选择其中一个岔路前进.如果选择的这个 ...

  4. Leetcode之深度优先搜索(DFS)专题-129. 求根到叶子节点数字之和(Sum Root to Leaf Numbers)

    Leetcode之深度优先搜索(DFS)专题-129. 求根到叶子节点数字之和(Sum Root to Leaf Numbers) 深度优先搜索的解题详细介绍,点击 给定一个二叉树,它的每个结点都存放 ...

  5. Leetcode之深度优先搜索(DFS)专题-301. 删除无效的括号(Remove Invalid Parentheses)

    Leetcode之深度优先搜索(DFS)专题-301. 删除无效的括号(Remove Invalid Parentheses) 删除最小数量的无效括号,使得输入的字符串有效,返回所有可能的结果. 说明 ...

  6. 图的深度优先遍历算法(DFS)

    搜索算法有很多种,本次文章主要分享图(无向图)的深度优先算法.深度优先算法(DFS)主要是应用于搜索中,早期是在爬虫中使用.其主要的思想有如下: 1.先访问一个节点v,然后标记为已被访问过2.找到第一 ...

  7. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  8. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  9. Swift2.0 中的String(三):类型转换

    本系列第三篇,String相关的类型转换.其他的几篇传送门(GitHub打不开链接的同学请自行把地址github改成gitcafe,或者直接去归档里找:-P): Swift2.0 中的String(一 ...

随机推荐

  1. luogu P1592 互质(欧拉函数)

    题意 (n<=106,k<=108) 题解 一开始以为是搜索. 但想想不对,翻了一眼题解发现是欧拉函数. 因为 gcd(a,b)=gcd(a,a+b) 所以和n互质的数应该是类似a1,a2 ...

  2. [读书]Python学习手冊--属性管理1

    属性管理-特性 一般开发这不必关心属性的实现.对工具的构建这来说,了解这一块对API的灵活性有帮助. 大多数情况下,属性位于对象自身之中.或者继承自对象所派生自的一个类. ----python学习手冊 ...

  3. UVALive 6084 Happy Camper(数学题)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  4. Light OJ 1080 - Binary Simulation

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1080 1080 - Binary Simulation PDF (Englis ...

  5. action support分析

    Action这一部分主要是数据(索引)的操作和部分集群信息操作. 所有的请求通过client转发到对应的action上然后再由对应的TransportAction来执行相关请求.如果请求能在本机上执行 ...

  6. Mysql-in查询问题

    Mysql-in查询问题 标签(空格分隔): mysql 问题:mysql用in语法查询出来的数据少了好多! 我的实际情况: 数据表: content字段记录着一些选项的id,多个选项用逗号隔开,比如 ...

  7. 5.不用拷贝的对象可以用ref

    #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost ...

  8. 3339: Rmq Problem

    Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1269  Solved: 665[Submit][Status][Discuss] Descripti ...

  9. 【C#Windows 服务】 《三》Timer设置

    一.工具: VS2015+NET Framework4.5. 二.操作: 1.计时器设置: 2.日志代码: 三.代码: 1.日志代码: 1 /// <summary> 2 /// Wind ...

  10. WIFI 概览

      概览 Android 提供默认 Android 框架实现,其中包括对各种 WLAN 协议和模式的支持,这些协议和模式包括: WLAN 基础架构 (STA) 网络共享模式或仅限本地模式下的 WLAN ...