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:
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
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"); }}
- UVA 620 Cellular Structure (dp)
- uva 620 Cellular Structure(dp?)
- UVa 620 Cellular Structure(DP)
- Cellular Structure - UVa 620 dp
- UVa 620 Cellular Structure(DP)
- uva 620 Cellular Structure
- UVA 620 Cellular Structure
- UVa 620 - Cellular Structure
- uva 620 - Cellular Structure
- UVa 620 - Cellular Structure
- Uva-620-Cellular Structure
- uva 620 Cellular Structure
- uva 620 - Cellular Structure
- UVA - 620 Cellular Structure
- UVa:620 Cellular Structure
- uva 620 Cellular Structure
- UVA - 620 Cellular Structure
- UVA 620 Cellular Structure
- K-means算法
- js中 onsubmit="submitTest();" 阻止默认事件
- DMM基础
- 最长公共子序列(LCS)
- js的for in循环和java里的foreach循环的区别
- Cellular Structure - UVa 620 dp
- linux下获得root权限运行程序
- SMB协议的共享文件读写
- 浅析Java虚拟机结构与机制
- 2014中国大数据国际高峰论坛
- 面向GC的Java编程
- 伏特加看是否已开始妇姑荷箪食
- 第2章 循环结构程序设计 习题
- js实现局部打印及其打印预览