22716_Cowlphabe

2022-5-16 18:22| 发布者: Hocassian| 查看: 20| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506887785899-Problem List-采集的数据-后羿采集器.html

Pro.ID

22716

Title

Cowlphabet

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22716

AC

6

Submit

24

Ratio

25.00%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Like all bovines, Farmer John's cows speak the peculiar 'Cow' language. Like so many languages, each word in this language comprises a sequence of upper and lowercase letters (A-Z and a-z).  A word is valid if and only if each ordered pair of adjacent letters in the word is a valid pair.

    Farmer John, ever worried that his cows are plotting against him, recently tried to eavesdrop on their conversation. He overheard one word before the cows noticed his presence. The Cow language is spoken so quickly, and its sounds are so strange, that all that Farmer John was able to perceive was the total number of uppercase letters, U (1 ≤ U ≤ 250) and the total number of lowercase letters, L (1 ≤ L ≤ 250) in the word.

    Farmer John knows all P (1 ≤ P ≤ 200) valid ordered pairs of adjacent letters.  He wishes to know how many different valid words are consistent with his limited data.  However, since this number may be very large, he only needs the value modulo 97654321.

    输入

    Line 1: Three space-separated integers: U, L and P

    Lines 2..P+1: Two letters (each of which may be uppercase or lowercase), representing one valid ordered pair of adjacent letters in Cow.

    输出

    Description

    Like all bovines, Farmer John's cows speak the peculiar 'Cow' language. Like so many languages, each word in this language comprises a sequence of upper and lowercase letters (A-Z and a-z).  A word is valid if and only if each ordered pair of adjacent letters in the word is a valid pair.

    Farmer John, ever worried that his cows are plotting against him, recently tried to eavesdrop on their conversation. He overheard one word before the cows noticed his presence. The Cow language is spoken so quickly, and its sounds are so strange, that all that Farmer John was able to perceive was the total number of uppercase letters, U (1 ≤ U ≤ 250) and the total number of lowercase letters, L (1 ≤ L ≤ 250) in the word.

    Farmer John knows all P (1 ≤ P ≤ 200) valid ordered pairs of adjacent letters.  He wishes to know how many different valid words are consistent with his limited data.  However, since this number may be very large, he only needs the value modulo 97654321.

    Input

    Line 1: Three space-separated integers: U, L and P

    Lines 2..P+1: Two letters (each of which may be uppercase or lowercase), representing one valid ordered pair of adjacent letters in Cow.

    Output

    Line 1: A single integer, the number of valid words consistent with Farmer John's data mod 97654321.

    Sample Input

    2 2 7
    AB
    ab
    BA
    ba
    Aa
    Bb
    bB

    Sample Output

    7

    Hint

    INPUT DETAILS:

    The word Farmer John overheard had 2 uppercase and 2 lowercase letters.  The valid pairs of adjacent letters are AB, ab, BA, ba, Aa, Bb and bB.

    OUTPUT DETAILS:

    The possible words are:

    AabB
    ABba
    abBA
    BAab
    BbBb
    bBAa
    bBbB

    Source

    样例输入

    2 2 7
    AB
    ab
    BA
    ba
    Aa
    Bb
    bB

    样例输出

    7

    提示

    INPUT DETAILS:

    The word Farmer John overheard had 2 uppercase and 2 lowercase letters.  The valid pairs of adjacent letters are AB, ab, BA, ba, Aa, Bb and bB.

    OUTPUT DETAILS:

    The possible words are:

    AabB
    ABba
    abBA
    BAab
    BbBb
    bBAa
    bBbB


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部