F - Fixing Banners

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 <bits/stdc++.h>
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"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
 } 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值