编程介的小学生 2019-12-27 22:29 采纳率: 20.5%
浏览 109

Rotate String 字符串的思路

Problem Description
Counting strings has been an interesting thing for Mr. Frog since he was 6 years old. Whenever given a string s, Mr. Frog may tell you how many strings in the same length are lexicographically smaller than or equal to s. But now, as an university student, elementary questions may not arouse Mr. Frog’s interest, so a harder question appeared.

We call a string t representative string if t is the lexicographically smallest string in an equivalence class of strings under rotation. Given s, Mr. Frog wants to know how many representative strings t, in the same length as s, are lexicographically smaller than or equal to s. In order to be a magician, you may want to solve this challenge quickly to attract Mr. Frog’s attention.

Only those t consisting of lowercase letters should be considered.

Input
The first line contains only one integer T(T≤30), which indicates the number of test cases.

For each test case, there is only one line describing the given string s(1≤|s|≤100), s consists of lowercase letters.

Output
For each test case, output one line “Case #x: y”, where x is the case number (starting from 1) and y is the number of representative strings to this question modulo 1000000007

Sample Input
2
bb
bab

Sample Output
Case #1: 27
Case #2: 651

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配