[BOJ 12465] Runs (Small)

View as PDF

Submit solution

Points: 5
Time limit: 5.0s
Memory limit: 512M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

I have a string S consisting of lower-case alphabetic characters, 'a' - 'z'. Each maximal sequence of contiguous characters that are the same is called a "run". For example, "bookkeeper" has 7 runs. How many different permutations of S have exactly the same number of runs as S?</p>

Two permutations a and b are considered different if there exists some index i at which they have a different character: a[i] ≠ b[i].

입력 형식

The first line of the input gives the number of test cases, T.  T lines follow. Each contains a single non-empty string of lower-case alphabetic characters, S, the string of interest.</p>

Limits

  • 1 ≤ T ≤ 100.
  • S is at least 1 character long.
  • S is at most 100 characters long.
## 출력 형식

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of different permutations of S that have exactly the same number of runs as S, modulo 1000003.

예제 입력

2
aabcd
bookkeeper

예제 출력

Case #1: 24
Case #2: 7200

Comments

There are no comments at the moment.