博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Live Archive 3490 - Generator 概率
阅读量:6992 次
发布时间:2019-06-27

本文共 1620 字,大约阅读时间需要 5 分钟。

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 

 

52 A2 ABA3 AAAAA26 ACMICPC26 ZJUZJU

 

Sample Output 

 

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

转载于:https://www.cnblogs.com/tobec/p/p0002.html

你可能感兴趣的文章
WampServer中MySQL中文乱码解决
查看>>
Codeforces-938D-Buy a Ticket(最短路设虚拟节点+Dijk优先队列优化)
查看>>
电商打折套路分析 —— Python数据分析练习
查看>>
HTTP请求、响应报文格式
查看>>
zendstudio中出现中文乱码的解决方法
查看>>
服务器端与客户端TCP连接入门(一)
查看>>
lombok使用方法
查看>>
多线程基础
查看>>
1028: C语言程序设计教程(第三版)课后习题8.2
查看>>
批量更新软连接脚本
查看>>
Linux 文件和目录的属性
查看>>
Log4j配置使用
查看>>
初步认识Hadoop
查看>>
jQuery对象扩展方法(Extend)深度解析
查看>>
9道前端技能编程题
查看>>
NOIP 2000年提高组复赛 单词接龙
查看>>
mysql-索引与优化
查看>>
sql server 2008安装需要一直重启。但重启后又没有达到效果。
查看>>
Psp个人软件开发工具
查看>>
uva 1395(kruskal变形)
查看>>