Cellular Structure - UVa 620 dp

本文介绍了一种用于识别细胞结构所处生命阶段的算法,通过分析细胞链序列,判断其处于简单阶段、完全生长阶段、突变阶段或诱变阶段。该算法通过输入细胞链数量及序列,输出每个序列对应的生长阶段描述。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 

4
A
AAB
BAAB
BAABA

Sample Output 

SIMPLE
FULLY-GROWN
MUTANT
MUTAGENIC

题意:一种结构由哪种标准结构最后演变过来,就输出相应的结构。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");
  }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值