cf Gym 101086F Hey JUDgE

F. Hey JUDgE
time limit per test
1.0 s
memory limit per test
256 MB
input
standard input
output
standard output

Since Judge Nicole Hosh moved to Egypt for her Computer Science Masters in AASTMT, in 2014, she has been training with coach Fegla and attending his camps in Egypt. She, also, set a number of problems for TCPC and JCPC and was a judge in LCPC and SCPC. Her best friend Noura was so proud of her so she was trying to convince her to start writing Codeforces Div. 2 round. After various attempts to convince her, Nicole finally agreed, and so, she started collecting some problems with different difficulties from her ex-contestant friends.

Judge Nicole collected 7 ideas for problems of different levels, she wants to create 5 problems for the next contest, one for each difficulty level, from A to E (difficulty 1 to 5). Given the difficulty level of the problems she currently has, she can merge the ideas of two problems, one of level x, and the other of level y to get a problem of level x + y.

For example, Judge Nicole can merge two problems of difficulties A and D, to get one problem of difficulty E (1 + 4 = 5).

Merging more than two problems into one will produce a problem with a long statement which is hard to explain, so she won’t do this (i.e., each problem is merged with another at most once). Also, she can’t merge a resultant problem again, and she can't use the same problem twice.

Input

The first line of input contains an integer T (1 ≤ T ≤ 330), the number of test cases.

Each test case will contain only one string S of length 7. Each letter of the string represents the difficulty level of a problem (from A to E), 'A' is the easiest and 'E' is the hardest.

Output

For each test case print "YES" if she can prepare a contest using the current problems, otherwise print "NO".

Examples
input
3
EBEABDA
CEDEACA
BDAAEAA
output
YES
NO
YES
Note

Warning: large Input/Output data, be careful with certain languages.


ac代码

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <set>
#define ll long long
using namespace std;
int t,b[15];
char a[15];
int vis[15],jdg;

void dfs(int x){
	if(x >= 6 || jdg){
		int flag=1;
		for(int i=1;i<=5;i++){
			/*printf("***%d***\n",vis[i]);*/
			if(!vis[i]){
				flag=0;
				break ;
			}
		}
		if(flag)
			jdg=1;
		
		return ;	
	}
	if(vis[x])
		dfs(x+1);
		
	for(int i=1;i<x;i++){
		if(vis[i] >= 2 ){
			vis[i]--;
			if(vis[x-i] >= 2){
				/*printf("**********\n");*/
				vis[x-i]--;
				vis[x]++;	
				dfs(x+1);
				vis[x-i]++;
				vis[x]--;
			}
			vis[i]++;
		}
	}
}

int main(){

	scanf("%d",&t);
	while(t--){
		scanf("%s",a);
		memset(vis,0,sizeof(vis));
		for(int i=0;i<7;i++){
			b[i]=a[i]-'A'+1;
			vis[b[i]]++;
		}
		/*for(int i=1;i<=5;i++)
			printf("vis[%d]==%d\n",i,vis[i]);*/
		if(vis[1]==0){
			printf("NO\n");
			continue ;
		}
		
		jdg=0;
		dfs(2);
		if(jdg)
			printf("YES\n");
		else
			printf("NO\n");
	}
		
	
	return 0;
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值