1. 程式人生 > >UVa 620 Cellular Structure(DP)

UVa 620 Cellular Structure(DP)

%d connect chain 結束 sid ntc none search cell

題意 有A,B兩種細胞 A細胞可由空生成 非空細胞鏈有兩種增長方式 設O為原非空細胞鏈 則O可增長為OAB或BOA 給你一個細胞鏈 若其是合法分裂的 要求推斷最後一次分裂是哪種方式 無法得到的輸出MUTANT

若給定的S是以AB結尾的 推斷去掉AB的部分是否合法就可以 若S是B開始A結束的 推斷去掉首尾是否合法就可以。


#include <cstdio>  
#include <cstring>  
char s[10000];  
bool dp(int i, int j)  
{  
    if (i == j)  
        return s[i] == 'A' ? 1 : 0;  
    else if (s[j - 1] == 'A' && s[j] == 'B')  
        return dp(i, j - 2);  
    else if (s[i] == 'B' && s[j] == 'A')  
        return dp(i + 1, j - 1);  
    return 0;  
}  
int main()  
{  
    int t;  
    scanf("%d", &t);  
    while (t--)  
    {  
        scanf("%s", s + 1);  
        int l = strlen(s + 1);  
        if (!strcmp(s, "A"))  
            printf("SIMPLE\n");  
        else if (s[l - 1] == 'A' && s[l] == 'B' && dp(1, l - 2))  
            printf("FULLY-GROWN\n");  
        else if (s[1] == 'B' && s[l] == 'A' && dp(2, l - 1))  
            printf("MUTAGENIC\n");  
        else  
            printf("MUTANT\n");  
    }  
    return 0;  
}

Cellular Structure

A chain of connected cells of two types A and B composes a cellular structure of some microorganisms of species APUDOTDLS.

If no mutation had happened during growth of an organism, its cellular chain would take one of the following forms:


技術分享
simple stage 		 O = A  
技術分享
fully-grown stage O = OAB 技術分享 mutagenic stage O = BOA

Sample notation O = OA means that if we added to chain of a healthy organism a cell A from the right hand side, we would end up also with a chain of a healthy organism. It would grow by one cell A.


A laboratory researches a cluster of these organisms. Your task is to write a program which could find out a current stage of growth and health of an organism, given its cellular chain sequence.

Input

A integer n being a number of cellular chains to test, and then n consecutive lines containing chains of tested organisms.

Output

For each tested chain give (in separate lines) proper answers:


		 SIMPLE 		 for simple stage
		 FULLY-GROWN 		 for fully-grown stage
		 MUTAGENIC 		 for mutagenic stage
		 MUTANT 		 any other (in case of mutated organisms)

If an organism were in two stages of growth at the same time the first option from the list above should be given as an answer.

Sample Input

4
A
AAB
BAAB
BAABA

Sample Output

SIMPLE
FULLY-GROWN
MUTANT
MUTAGENIC



UVa 620 Cellular Structure(DP)