SPOJ ACODE

394. Alphacode

 * https://spoj.com/problems/ACODE/

Also seen at:
 * http://acm.csie.ntu.edu.tw/ntujudge/problem.php?id=105
 * http://acm.tju.edu.cn/toj/showp1541.html
 * http://acm.zju.edu.cn/show_problem.php?pid=2202
 * http://acm.pku.edu.cn/JudgeOnline/problem?id=2033

Source: East Central North America 2004

Summary
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.

Explanation
This is a dynamic programming problem.

If we take a single number $$a$$, the problem will be in a single state. If you want to add another number $$b$$ to the problem, the problem could be in one of two states:
 * The two numbers printed one after another, $$ab$$
 * The two numbers combined to form a different single number, $$c$$ $$(a*10+b)$$

One or both of the above states may be valid. If the first one remains valid$$(b\ne0)$$, the new state is $$b$$. If the second remains valid $$(1\le c\le26)$$ then the state is $$c$$. For each of the two valid states, keep track of the previous valid states that lead to it.

Gotchas

 * The result is a 64-it integer - make sure intermediate calculations use that data type.
 * String "110" only has one possible encoding.

Input
 25114 1111111111 3333333333 226210 0 

Output
 6 89 1 3 