Also seen at:
Source: East Central North America 2004
Two people want to send coded messages to each other. One possible encoding scheme is to simply replace each letter with its numerical value in the alphabet and then string all the digits together without spaces. Determine the number of possible ways to decode a message encoded this way.
This is a dynamic programming problem.
If we take a single number , the problem will be in a single state. If you want to add another number to the problem, the problem could be in one of two states:
- The two numbers printed one after another,
- The two numbers combined to form a different single number,
One or both of the above states may be valid. If the first one remains valid, the new state is . If the second remains valid then the state is . For each of the two valid states, keep track of the previous valid states that lead to it.
- The result is a 64-bit integer - make sure intermediate calculations use that data type.
- String "110" only has one possible encoding.
25114 1111111111 3333333333 226210 0
6 89 1 3