Cellular Structure - UVa 620 dp

来源:互联网 发布:java人才培训中心 编辑:程序博客网 时间:2024/06/07 11:19

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:

$\bullet$simple stage  O = A  $\bullet$fully-grown stage  O = OAB $\bullet$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 

4AAABBAABBAABA

Sample Output 

SIMPLEFULLY-GROWNMUTANTMUTAGENIC

题意:一种结构由哪种标准结构最后演变过来,就输出相应的结构。SIMPLE表示只有一个A;FULLY-GROWN表示由一种标准结构右边加上AB;MUTAGENIC表示由一种标准结构左边加上B,右边加上A。

思路:直接看代码吧,感觉这dp写得跟搜索似的。

AC代码如下:

#include<cstdio>#include<cstring>using namespace std;bool flag[4];char s[1001];int len;bool dp(int l,int r){ if(l>r || l+1==r)   return false;  if(l==r)    return s[l]=='A';  if(s[r-1]=='A' && s[r]=='B' && dp(l,r-2))   return true;  if(s[l]=='B' && s[r]=='A' && dp(l+1,r-1))   return true;  return false;}int main(){ int t,n,i,j,k;  scanf("%d",&t);  while(t--)  { scanf("%s",s+1);    len=strlen(s+1);    if(len==1 && s[1]=='A')     printf("SIMPLE\n");    else if(s[len-1]=='A' && s[len]=='B' && dp(1,len-2))     printf("FULLY-GROWN\n");    else if(s[1]=='B' && s[len]=='A' && dp(2,len-1))     printf("MUTAGENIC\n");    else     printf("MUTANT\n");  }}



0 0