UVA620- Cellular Structure

题意:有三种形态的细胞排列,除了这三种,其他都为细胞变异。求所给出的细胞序列处于哪种阶段,或者是变异的。


思路:用dfs搜索,判断细胞序列处于哪个状态,输出最高的那个状态


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int MAXN = 105;

char str[MAXN];

int dfs(int b, int e) {
    if (b == e && str[b] == 'A')
        return 1;
    if (e - b >= 1 && str[e] == 'A' && dfs(b, e - 1))
        return 1;
    if (e - b >= 2 && str[e] == 'B' && str[e - 1] == 'A' && dfs(b, e - 2))
        return 2;
    if (e - b >= 2 && str[b] == 'B' && str[e] == 'A' && dfs(b + 1, e - 1))
        return 3;
    return 0;
}

int main() {
    int cas;
    scanf("%d", &cas);
    while (cas--) {
        scanf("%s", str); 
        int len = strlen(str);
        int ans = dfs(0, len - 1);
        if (ans == 1)
            printf("SIMPLE\n");
        else if (ans == 2)
            printf("FULLY-GROWN\n");
        else if (ans == 3)
            printf("MUTAGENIC\n");
        else
            printf("MUTANT\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值