描述
Acm, a treasure-explorer, is exploring again. This time he is in a special maze, in which there are some doors (at most 5 doors, represented by 'A', 'B', 'C', 'D', 'E' respectively). In order to find the treasure, Acm may need to open doors. However, to open a door he needs to find all the door's keys (at least one) in the maze first. For example, if there are 3 keys of Door A, to open the door he should find all the 3 keys first (that's three 'a's which denote the keys of 'A' in the maze). Now make a program to tell Acm whether he can find the treasure or not. Notice that Acm can only go up, down, left and right in the maze.
输入
The input consists of multiple test cases. The first line of each test case contains two integers M and N (1 < N, M < 20), which denote the size of the maze. The next M lines give the maze layout, with each line containing N characters. A character is one of the following: 'X' (a block of wall, which the explorer cannot enter), '.' (an empty block), 'S' (the start point of Acm), 'G' (the position of treasure), 'A', 'B', 'C', 'D', 'E' (the doors), 'a', 'b', 'c', 'd', 'e' (the keys of the doors). The input is terminated with two 0's. This test case should not be processed.
输出
For each test case, in one line output "YES" if Acm can find the treasure, or "NO" otherwise.
翻译
描述
Acm,一个寻宝者,又开始了探索。这次他在一个有一些门的迷宫中(最多五扇门,用A,B,C,D,E代表)。为了找到财宝,Acm可能需要打开这些门。然而,他需要先在迷宫中找到这些门的钥匙(至少一把)才能打开它们。例如,如果打开门A需要三把钥匙,那么他需要把三把钥匙全部找到才能打开A门(迷宫中有三个“a”代表这三把钥匙)。现在写一个程序告诉Acm他是否能找到财宝。注意Acm在迷宫中只能向前后左右走动。
输入
输入由多个测试样例组成。每个样例的第一行包含两个整数M和N(1<N,M<20),代表迷宫的大小。接下来的M行给出了迷宫的排布,每一行包含N个字符。字符可能是一下内容:“X”(代表一堵墙,探索者不能够进入);“.”(空的通道);“S”(Acm开始的位置);“G”,(财宝的位置);“A,B,C,D,E”(门);“a,b,c,d,e”(门的钥匙)。输入以两个“0”表示结束。
输出
对于每个测试数据,输出“YES”如果Acm能获得财宝,否则输出“NO”。