您的位置:首页 > 其它

Cellular Structure+uva+简单区间dp

2014-09-27 09:15 176 查看
Cellular Structure
Time Limit: 3000MSMemory Limit: Unknown64bit IO Format: %lld & %llu
Description

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 consecutivelines 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
解决方案:开始理解题目有点困难,后面才懂。O=A 即只有A细胞的一个organism,O=OAB 即以AB细胞结尾的organism,O=BOA 即以B开头A结尾的organism,O代表organism。dp[i][j][k],代表i到j区间,k代表那几种organism。所以可以从下往上更新:
先是:
1)dp[i][i][1]=1 当str[i]=='A'
2)dp[i][j][2]=dp[i][j-2][1]|dp[i][j-2][2]|dp[i][j-2][3] 当str[j-1]=='A'&&str[j]=='B';
3)dp[i][j][3]=dp[i+1][j-1][1]|dp[i+1][j-1][2]|dp[i+1][j-1][3] 当str[i]=='A'&&str[j]=='B';
code:
#include <iostream>#include<cstring>#include<string>#include<cstdio>using namespace std;char text[1000];int dp[1000][1000][4];int main(){int t;scanf("%d",&t);while(t--){scanf("%s",text+1);memset(dp,0,sizeof(dp));int len=strlen(text+1);for(int i=1; i<=len; i++){if(text[i]=='A') dp[i][i][1]=1;}for(int i=2; i<=len; i++){for(int j=1; j+i<=len; j++){if(text[j+i-1]=='A'&&text[j+i]=='B'){dp[j][j+i][2]=dp[j][j+i-2][1]|dp[j][j+i-2][3]|dp[j][j+i-2][2];}if(text[j]=='B'&&text[j+i]=='A'){dp[j][j+i][3]=dp[j+1][j+i-1][1]|dp[j+1][j+i-1][2]|dp[j+1][j+i-1][3];}}}if(dp[1][len][1]){printf("SIMPLE\n");}else if(dp[1][len][2]){printf("FULLY-GROWN\n");}else if(dp[1][len][3]){printf("MUTAGENIC\n");}else{printf("MUTANT\n");}}return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: