码迷,mamicode.com
首页 > 其他好文 > 详细

【UVA】620-Cellular Structure(递推)

时间:2014-09-04 17:06:25      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   io   ar   2014   art   cti   

读错题了一开始。

一个细胞每次可以进行3中增值方式,给你一个最终形态,问你达到这个形态之前的那个到这个最终形态是通过哪一种方式得到的。

直接递推就可以了,小优化就是如果这个字符串长度为偶数,那么肯定发生了变异。

14144659 620 Cellular Structure Accepted C++ 0.009 2014-09-04 07:31:52


#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<iostream>
using namespace std;
#define MAXD 10000 + 10
char str[MAXD];
int dfs(int start , int last){
    if(start == last && str[start] == 'A')
        return 1;
    if(last - 2 >= start && str[last] == 'B' && str[last - 1] == 'A' && dfs(start,last - 2))
        return 2;
    if((last - 1 >= start + 1) && str[start] == 'B' && str[last] == 'A' && dfs(start + 1 , last - 1))
        return 3;
    return 0;
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%s",str);
        int L = strlen(str);
        if(L != 1 && !(L & 1))
            printf("MUTANT\n");
        else{
        switch(dfs(0,L - 1)){
            case 1 : printf("SIMPLE\n");       break;
            case 2 : printf("FULLY-GROWN\n"); break;
            case 3 : printf("MUTAGENIC\n");    break;
            case 0 : printf("MUTANT\n");       break;
        }
        }
    }
    return 0;
}

【UVA】620-Cellular Structure(递推)

标签:style   http   color   os   io   ar   2014   art   cti   

原文地址:http://blog.csdn.net/u013451221/article/details/39053739

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!