21821_Generator

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

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

Pro.ID

21821

Title

Generator

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    We can generate a random string by generating a sequence of random characters and concatenating them together. Each character is chosen independently from the first n letters in the English alphabet with equal probability. Only capital letters are used in this problem. The generation is stopped as soon as one of specific patterns occurs in the random string.

    Your task is to predict the expected length of the generated string.

    输入

    Standard input will contain multiple test cases.

    First line is the number of case x.

    Each test case consists of integer N ( 1 ≤ N ≤ 8 ) which is the number of letters used, and M ( 1 ≤ M ≤ 10 ) which is the number of patterns used. The following M lines contain the patterns which are non-empty strings consisting of letters chosen from the first N upper case English letters. The length of any pattern will not exceed 10.

    输出

    Description

    We can generate a random string by generating a sequence of random characters and concatenating them together. Each character is chosen independently from the first n letters in the English alphabet with equal probability. Only capital letters are used in this problem. The generation is stopped as soon as one of specific patterns occurs in the random string.

    Your task is to predict the expected length of the generated string.

    Input

    Standard input will contain multiple test cases.

    First line is the number of case x.

    Each test case consists of integer N ( 1 ≤ N ≤ 8 ) which is the number of letters used, and M ( 1 ≤ M ≤ 10 ) which is the number of patterns used. The following M lines contain the patterns which are non-empty strings consisting of letters chosen from the first N upper case English letters. The length of any pattern will not exceed 10.

    Output

    For each test case, print the expected length of the generated random string. All output numbers are rounded to the second digit after the decimal point.

    Sample Input

    4
    2 1
    A
    2 1
    ABA
    3 1
    AAAAA
    2 2
    A
    AA

    Sample Output

    2.00
    10.00
    363.00
    2.00

    Source

    样例输入

    4
    2 1
    A
    2 1
    ABA
    3 1
    AAAAA
    2 2
    A
    AA

    样例输出

    2.00
    10.00
    363.00
    2.00

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部