#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 must contain only decimal digits in the range through , inclusive, and it must contain at least one digit greater than . Leading zeroes are allowed. For example, and are valid googlements of length . (which contains a digit, , greater than the length of the googlement, ) and (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 , count the number of s in the googlement (which could be ) and write down that value, then count the number of s in the googlement (which could be ) 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 s. The new string generated in this way represents the new googlement, and it will also have length . It is even possible for a googlement to decay into itself!
For example, suppose that the googlement has just appeared. This has one , zero s, zero s, and two s, so it will decay into the googlement . This has one , one , zero s, and zero s, so it will decay into , which will decay into , which will decay into , which will decay into , which will continuously decay into itself.
You have just observed a googlement . 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, . test cases follow. Each consists of one line with a string , representing a googlement.
输出格式
For each test case, output one line containing Case #x: y
, where is the test case number (starting from 1) and 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 , or it could have decayed from , which could have itself decayed from or . 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 , which is the only possible googlement of length .
In sample case #3, the googlement must have been ; no other googlement could have decayed into it.
Limits
- .
- Each digit in is a decimal digit between and the length of , inclusive.
- contains at least one non-zero digit.
Small dataset (3 Pts, Test Set 1 - Visible)
- Time limit:
205 seconds. - the length of G .
Large dataset (10 Pts, Test Set 2 - Hidden)
- Time limit:
6015 seconds. - the length of G .