原题:
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
题目大意:
(真题看了n久才看懂),告诉你有一个链式结构,这个结构有4种生长方式,一种是A,就是只有一个A。另外一种是OAB,就是在原来的链式上加上AB,或者只有AB。第三种是在BOA,在原来的链的后面加个B,在前面加个A。第四种就是不满足上面3种的结构。
思路见代码下方:
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<stack>
using namespace std;
string str;
bool dfs(int s,int e)
{
if(e==s&&str[s]=='A')
return true;
if(e-s==1&&str[s]=='A'&&str[e]=='B')
return true;
if(str[e]=='B'&&str[e-1]=='A')
{
if(dfs(s,e-2))
return true;
}
if(str[s]=='B'&&str[e]=='A')
{
if(dfs(s+1,e-1))
return true;
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
int n,flag;
cin>>n;
while(n--)
{
cin>>str;
flag=1;
if(str=="A")
{
cout<<"SIMPLE"<<endl;
flag=0;
}
else
{
if(str[str.size()-1]=='B'&&str[str.size()-2]=='A')
{
if(dfs(0,str.size()-1))
{
cout<<"FULLY-GROWN"<<endl;
flag=0;
}
}
else
{
if(str[0]=='B'&&str[str.size()-1]=='A')
{
if(dfs(0,str.size()-1))
{
cout<<"MUTAGENIC"<<endl;
flag=0;
}
}
}
}
if(flag)
cout<<"MUTANT"<<endl;
}
return 0;
}
思路:
我在UVATOOKIT上测试数据的时候看到标签上贴个DP,还以为自己的代码会超时,结果0秒过了。
就是用简单的搜索,找每次寻找当前结构是否符合三种基本生长结构即可。 另外,这题怎么dp呢?