精选文章 F - Fixing Banners

F - Fixing Banners

作者:、叮叮叮当 时间: 2019-11-05 05:36:05
、叮叮叮当 2019-11-05 05:36:05

Harbin, whose name was originally a Manchu word meaning "a place for drying fishing nets", grew from a small rural settlement on the Songhua River to become one of the largest cities in Northeast China. Founded in 1898 with the coming of the Chinese Eastern Railway, the city first prospered as a region inhabited by an overwhelming majority of the immigrants from the Russian Empire. Now, Harbin is the capital of Heilongjiang province and the largest city in the northeastern region of the People's Republic of China. It serves as a key political, economic, scientific, cultural, and communications hub in Northeast China, as well as an important industrial base of the nation.

This year, a CCPC regional contest is going to be held in this wonderful city, hosted by Northeast Forestry University. To ensure the contest will be a success and enjoyed by programmers around the country, preparations for the event are well underway months before the contest.

You are the leader of a student volunteer group in charge of making banners to decorate the campus during the event. Unfortunately, your group made a mistake and misprinted one of the banners. To be precise, the word "harbin" is missing in that banner. Because you don't have time to reprint it, the only way to fix it is to cut letters from some used old banners and paste them onto the misprinted banner. You have exactly six banners, and for some reason, you must cut exactly one letter from each banner. Then, you can arrange and paste the six letters onto the misprinted banner and try to make the missing word "harbin". However, before you start cutting, you decide to write a program to see if this is possible at all.

Input

The input contains multiple cases. The first line of the input contains a single integer T (1≤T≤50000)T (1≤T≤50000), the number of cases.

For each case, the input contains six lines. Each line contains a non-empty string consisting only of lowercase English letters, describing the letters on one of the old banners.

The total length of all strings in all cases doesn't exceed 2⋅1062⋅106.

Output

For each case, print the string "Yes" (without quotes) if it is possible to make the word "harbin", otherwise print the string "No" (without quotes).

Example

Input

2
welcome
toparticipate
inthe
ccpccontest
inharbin
inoctober
harvest
belong
ninja
reset
amazing
intriguing

Output

No
Yes

题解

F Fixing Banners
Shortest judge solution: 580 Bytes.
签到题, 6! 枚举所有情况或者状压 DP 都可以通过。
然而我却是在网上看的dfs搜图过得
代码如下
#include 
using namespace std;
int vis[8][8];
int v[8];
int flag;
void bfs(int num)
{
	if(flag) return ;
	if(num>=6)
	{
		flag=1;
		return;
	}
	for(int i=0;i<6;i++)
	{
		if(!v[i]&&vis[i][num])
		{
			v[i]=1;
			bfs(num+1);
			v[i]=0;
		}
	}
}
int main()
{
	int t;
	cin>>t;
	int p=t;
	while(t--)
	{
		if(p == t + 1)
            getchar();
		flag=0;
		char ch;
		memset(vis,0,sizeof(vis));
		memset(v,0,sizeof(v));
		for(int i=0;i<6;i++)
		{
			while(ch=getchar())
			{
				if(ch=='\n') break;
				else if(ch=='h')
				{
					vis[i][0]=1;
				}
				else if(ch=='a')
				{
					vis[i][1]=1;
				}
				else if(ch=='r')
				{
					vis[i][2]=1;
				}
				else if(ch=='b')
				{
					vis[i][3]=1;
				}
				else if(ch=='i')
				{
					vis[i][4]=1;
				}
				else if(ch=='n')
				{
					vis[i][5]=1;
				}
			}
		}
		bfs(0);
		if(flag)
		{
			cout<<"Yes"<

 

 

勿删,copyright占位
分享文章到微博
分享文章到朋友圈

上一篇:Markdown添加图片

下一篇:简单理解TCP/IP五层,OSI七层协议

您可能感兴趣

华为云40多款云服务产品0元试用活动

免费套餐,马上领取!
CSDN

CSDN

中国开发者社区CSDN (Chinese Software Developer Network) 创立于1999年,致力为中国开发者提供知识传播、在线学习、职业发展等全生命周期服务。