zoukankan      html  css  js  c++  java
  • Live Archive 3490

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=214&page=show_problem&problem=1491

    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 <tex2html_verbatim_mark>letters in the English alphabet with equal probability. Only capital letters are used in this problem. The generation is stopped as soon as a specific pattern 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. The first line of the input is a single integer T <tex2html_verbatim_mark>(1$ le$T$ le$10)<tex2html_verbatim_mark>which is the number of test cases. T <tex2html_verbatim_mark>test cases follow, each preceded by a single blank line.

    Each test case consists of a single integer N <tex2html_verbatim_mark>(1$ le$N$ le$26) <tex2html_verbatim_mark>which is the number of letters used, and a pattern, which is a non-empty string consisting of letters chosen from the first N <tex2html_verbatim_mark>upper case English letters. The length of any pattern will not exceed 12.

    Output 

    Results should be directed to standard output. Start each case with ``Case # <tex2html_verbatim_mark>:" on a single line, where # <tex2html_verbatim_mark>is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

    For each test case, print the expected length of the generated random string.

    Sample Input 

    5
    
    2 A
    
    2 ABA
    
    3 AAAAA
    
    26 ACMICPC
    
    26 ZJUZJU
    

    Sample Output 

    Case 1:
    2
    
    Case 2:
    10
    
    Case 3:
    363
    
    Case 4:
    8031810176
    
    Case 5:
    308933352


  • 相关阅读:
    Win10创意者更新秋季版激活秘籍
    将刷了Android的Lumia恢复为WP系统
    给Lumia 520/521/525/526/720刷Android系统
    DNS解析
    遍历对象目录
    PE注入
    利用NtCreateThreadEx注入
    利用CreateRemoteThread注入
    APC注入
    SetWindowHookEx()注入
  • 原文地址:https://www.cnblogs.com/tobec/p/p0002.html
Copyright © 2011-2022 走看看