zoukankan      html  css  js  c++  java
  • UVA 620 Cellular Structure (dp)

     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:

     

    
    $ullet$
    simple stage 		 O = A  
    $ullet$
    fully-grown stage 		 O = OAB 
    $ullet$
    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
    

    题意:如题,一个细胞有三种生长方式。求出当前细胞的上一个生长方式。
    思路:由当前细胞一直往之前的状态找即可。直到找到结束或者不能再往下找了位置。
    代码:

     

    #include <stdio.h>
    #include <string.h>
    
    int t, len;
    char ans[4][20] = {"SIMPLE", "FULLY-GROWN", "MUTANT", "MUTAGENIC"};
    char str[1005];
    
    int dp(int start, int end) {
    	if (end - start == 1 && str[start] == 'A') {
    		return 0;
    	}
    	else if (str[start] == 'B' && str[end - 1] == 'A') {
    		if (dp(start + 1, end - 1) != 2) {
    			return 3;
    		}
    	}
    	else if (str[end - 1] == 'B' && str[end - 2] == 'A') {
    		if (dp(start, end - 2) != 2) {
    			return 1;
    		}
    	}
    	return 2;
    }
    int main() {
    	scanf("%d%*c", &t);
    	while (t --) {
    		gets(str);
    		len = strlen(str);
    		printf("%s
    ", ans[dp(0, len)]);
    	}
    	return 0;
    }


    
    
  • 相关阅读:
    luogu P1840 Color the Axis_NOI导刊2011提高(05)|并查集
    luogu P5414 [YNOI2019]排序 |动态规划
    luogu P4064 [JXOI2017]加法 |二分+堆
    luogu P4065 [JXOI2017]颜色 |随机化+前缀和
    luogu P2135 方块消除 |dp
    luogu P1650 田忌赛马 |贪心
    IM群聊消息究竟是存1份(即扩散读)还是存多份(即扩散写)?
    IM群聊消息的已读回执功能该怎么实现?
    IPv6技术详解:基本概念、应用现状、技术实践(下篇)
    IPv6技术详解:基本概念、应用现状、技术实践(上篇)
  • 原文地址:https://www.cnblogs.com/pangblog/p/3299431.html
Copyright © 2011-2022 走看看