读了几遍题,还不知道题的意思,唉,理解能力啊,看了别人的代码之后,奥,原来是这样,这里简单说一下对题目的理解,它说我们有这样一个细胞链,其中细胞只有A和B两种,给你这个细胞链让你看一下,是不是经过所给的三种状态,可以变化成现在的状态,然后输出现在处于什么状态。的确像个DPS。
代码如下:
#include<stdio.h>
#include<string.h>
#define MAXN 100100
int n, stage;
char c[MAXN];
char t[4][20] = {"SIMPLE","FULLY-GROWN","MUTAGENIC","MUTANT"};
void dp(int head, int last, int flag)
{
if(head == last)
{
if(c[head] == 'A')
{
if(flag)
stage = 1, flag = 0;
}
else stage = 4;
}
else if(last - head >= 2)
{
if(c[last] == 'B'&&c[last-1] == 'A')
{
if(flag)
stage = 2, flag = 0;
dp(head, last-2,flag);
}
else if(c[head] == 'B' && c[last] == 'A')
{
if(flag)
stage = 3, flag = 0;
dp(head+1, last-1,flag);
}
else stage = 4;
}
else stage = 4;
}
void input()
{
while(scanf("%d",&n) == 1)
for(int i = 0; i < n; i ++)
{
scanf("%s", c);
int len = strlen(c);
int rear = len - 1;
int first = 0;
dp(first,rear,1);
printf("%s\n",t[stage-1]);
}
}
int main()
{
input();
return 0;
}