• lightoj1051_dp


    http://lightoj.com/volume_showproblem.php?problem=1051

    1051 - Good or Bad
    Time Limit: 2 second(s) Memory Limit: 32 MB

    A string is called bad if it has 3 vowels in a row, or 5 consonants in a row, or both. A string is called good if it is not bad. You are given a string s, consisting of uppercase letters ('A'-'Z') and question marks ('?'). Return "BAD" if the string is definitely bad (that means you cannot substitute letters for question marks so that the string becomes good), "GOOD" if the string is definitely good, and "MIXED" if it can be either bad or good.

    The letters 'A', 'E', 'I', 'O', 'U' are vowels, and all others are consonants.

    Input

    Input starts with an integer T (≤ 200), denoting the number of test cases.

    Each case begins with a non-empty string with length no more than 50.

    Output

    For each case of input you have to print the case number and the result according to the description.

    Sample Input

    Output for Sample Input

    5

    FFFF?EE

    HELLOWORLD

    ABCDEFGHIJKLMNOPQRSTUVWXYZ

    HELLO?ORLD

    AAA

    Case 1: BAD

    Case 2: GOOD

    Case 3: BAD

    Case 4: MIXED

    Case 5: BAD

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <cstdio>
     6 #include <vector>
     7 #include <ctime>
     8 #include <queue>
     9 #include <list>
    10 #include <set>
    11 #include <map>
    12 using namespace std;
    13 #define INF 0x3f3f3f3f
    14 typedef long long LL;
    15 
    16 int dp[55][10][10]; //dp[i][j][k],表示以第i位为结尾,元音个数为j或辅音个数为k的情况是否存在
    17 char s[55];
    18 int main()
    19 {
    20     int t;
    21     scanf("%d", &t);
    22     for(int ca = 1; ca <= t; ca++)
    23     {
    24         scanf("%s", s+1);
    25         int len = strlen(s+1);
    26         memset(dp, 0, sizeof(dp));
    27         dp[0][0][0] = 1;
    28         int Bad = 0, Good = 0;
    29         for(int i = 1; i <= len; i++)
    30         {
    31             for(int j = 0; j < 3; j++)
    32             {
    33                 if(dp[i-1][j][0] == 0)
    34                     continue;
    35                 if(s[i] == '?')
    36                     dp[i][j+1][0] = dp[i][0][1] = 1;
    37                 else if(s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')
    38                     dp[i][j+1][0] = 1;
    39                 else
    40                     dp[i][0][1] = 1;
    41             }
    42             if(dp[i][3][0])
    43                 Bad = 1;
    44             for(int j = 0; j < 5; j++)
    45             {
    46                 if(dp[i-1][0][j] == 0)
    47                     continue;
    48                 if(s[i] == '?')
    49                     dp[i][0][j+1] = dp[i][1][0] = 1;
    50                 else if(s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')
    51                     dp[i][1][0] = 1;
    52                 else
    53                     dp[i][0][j+1] = 1;
    54             }
    55             if(dp[i][0][5])
    56                 Bad = 1;
    57         }
    58         for(int i = 1; i < 3; i++)
    59             if(dp[len][i][0])
    60                 Good = 1;
    61         for(int i = 1; i < 5; i++)
    62             if(dp[len][0][i])
    63                 Good = 1;
    64         printf("Case %d: ", ca);
    65         if(Bad && Good)
    66             puts("MIXED");
    67         else if(Bad)
    68             puts("BAD");
    69         else
    70             puts("GOOD");
    71     }
    72     return 0;
    73 }
  • 相关阅读:
    解决Requires: libc.so.6(GLIBC_2.14)(64bit)错误解决方法
    Linux下安装rpm出现error: Failed dependencies
    使用WordPress搭建个人博客
    Log4j不写入日志文件排错记录
    JAVA EE,JAVA SE,JAVA ME,JDK,JRE,JVM之间的区别
    [转]【maven】解决Missing artifact jdk.tools:jdk.tools:jar:1.6
    Eclipse新建项目介绍
    Android开发-API指南-<permission-group>
    Android开发-API指南-<permission>
    Android开发-API指南-<path-permission>
  • 原文地址:https://www.cnblogs.com/luomi/p/5955815.html
Copyright © 2020-2023  润新知