HDOJ 5311-Hidden String【深搜】
来源:互联网 发布:sql union什么意思 编辑:程序博客网 时间:2024/06/07 13:12
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 ofs[l1..r1] , s[l2..r2] , s[l3..r3] is "anniversary".
1.
2. The concatenation of
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 strings (1≤|s|≤100) consisting of lowercase English letters.
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
2annivddfdersewwefarynniversarya
Sample Output
YESNO
解题思路
因为这个题中长度比较小可以暴力搞一下,利用深搜写在判断里判断是否满足段数大于三,然后继续深搜。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int len,len1;char map[100000];char moxing[20]="anniversary";bool f(int x,int y,int ci){int i;if(ci<=3&&y>=len1){return true;}else if(ci>3){return false;}for(i=x;i<len;i++){int wc,wcnm;wc=i,wcnm=y;while(wc<len&&wcnm<len1&&map[wc]==moxing[wcnm]){wc++;wcnm++;}if(wc>i&&f(wc,wcnm,ci+1)){return true;}}return false;}int main(){int t;scanf("%d",&t);while(t--){scanf("%s",map);len=strlen(map);len1=strlen(moxing);bool cnm=f(0,0,0);if(cnm==true)printf("YES");elseprintf("NO");printf("\n");}return 0;}
0 0
- HDOJ 5311-Hidden String【深搜】
- HDOJ 5311 Hidden String(枚举)
- hdoj 5311 Hidden String 【dfs】
- HDOJ-----5311---Hidden String---暴力
- hdoj 5311 Hidden String 【KMP + 暴力】
- hdoj 5311 Hidden String 【dfs(递归)】【周赛】
- hdoj 5311 Hidden String (暴力枚举)
- HDOJ 5533-Hidden String
- Hidden String 5311 (深搜+字符串)
- HDOJ 5311 Hidden String(DFS不错的题)
- hdoj--1034--Hidden String(dfs)
- HDU 5311:Hidden String
- HDU 5311 Hidden String
- hdu 5311 Hidden String
- Hidden String(5311)
- hdu 5311 Hidden String
- hdu 5311 Hidden String
- HDU 5311 Hidden String
- Windows JDK 1.8降级为1.7方法
- 瀑布流效果
- 带你走进ajax(4)
- 解决RecyclerView中使用UIL加载网络图片,在刷新时出现闪烁问题
- dedecms标签
- HDOJ 5311-Hidden String【深搜】
- float和decimal的区别
- 在U盘上安装ChromiumOS
- 基于Wolf32F031 自由评估板的KEY scan(查询方式)实验硬件原理及软件API使用方法(适用于STM32F030/031)
- 把彩色图像变成灰度图像
- 为何1M的网络下载速度只有120k/s
- 深搜与广搜
- hdoj--1034--Hidden String(dfs)
- 基于Wolf32F031 自由评估板的Buzzer(PWM控制方式)实验硬件原理及软件API使用方法(适用于STM32F030/031)