#P13175. [GCJ 2017 #3] Googlements

[GCJ 2017 #3] Googlements

题目描述

Chemists work with periodic table elements, but here at Code Jam, we have been using our advanced number smasher to study googlements. A googlement is a substance that can be represented by a string of at most nine digits. A googlement of length LL must contain only decimal digits in the range 00 through LL, inclusive, and it must contain at least one digit greater than 00. Leading zeroes are allowed. For example, 103103 and 001001 are valid googlements of length 33. 400400 (which contains a digit, 44, greater than the length of the googlement, 33) and 000000 (which contains no digit greater than 0) are not.

Any valid googlement can appear in the world at any time, but it will eventually decay into another googlement in a deterministic way, as follows. For a googlement of length LL, count the number of 11s in the googlement (which could be 00) and write down that value, then count the number of 22s in the googlement (which could be 00) and write down that value to the right of the previous value, and so on, until you finally count and write down the number of LLs. The new string generated in this way represents the new googlement, and it will also have length LL. It is even possible for a googlement to decay into itself!

For example, suppose that the googlement 04140414 has just appeared. This has one 11, zero 22s, zero 33s, and two 44s, so it will decay into the googlement 10021002. This has one 11, one 22, zero 33s, and zero 44s, so it will decay into 11001100, which will decay into 20002000, which will decay into 01000100, which will decay into 10001000, which will continuously decay into itself.

You have just observed a googlement GG. This googlement might have just appeared in the world, or it might be the result of one or more decay steps. What is the total number of possible googlements it could have been when it originally appeared in the world?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each consists of one line with a string GG, representing a googlement.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the number of different googlements that the observed googlement could have been when it first appeared in the world.

3
20
1
123
Case #1: 4
Case #2: 1
Case #3: 1

提示

Sample Explanation

In sample case #1, the googlement could have originally been 2020, or it could have decayed from 1111, which could have itself decayed from 1212 or 2121. Neither of the latter two could have been a product of decay. So there are four possibilities in total.

In sample case #2, the googlement must have originally been 11, which is the only possible googlement of length 11.

In sample case #3, the googlement must have been 123123; no other googlement could have decayed into it.

Limits

  • 1T1001 \leq T \leq 100.
  • Each digit in GG is a decimal digit between 00 and the length of GG, inclusive.
  • GG contains at least one non-zero digit.

Small dataset (3 Pts, Test Set 1 - Visible)

  • Time limit: 20 5 seconds.
  • 11 \leq the length of G 5\leq 5.

Large dataset (10 Pts, Test Set 2 - Hidden)

  • Time limit: 60 15 seconds.
  • 11 \leq the length of G 9\leq 9.