# SPOJ ACODE

## 394. Alphacode

Also seen at:

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 ${\displaystyle a}$, the problem will be in a single state. If you want to add another number ${\displaystyle b}$ to the problem, the problem could be in one of two states:

• The two numbers printed one after another, ${\displaystyle ab}$
• The two numbers combined to form a different single number, ${\displaystyle c}$ ${\displaystyle (a*10+b)}$

One or both of the above states may be valid. If the first one remains valid${\displaystyle (b\neq 0)}$, the new state is ${\displaystyle b}$. If the second remains valid ${\displaystyle (1\leq c\leq 26)}$ then the state is ${\displaystyle 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 9, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5475031137466431, "perplexity": 721.7048525721889}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-35/segments/1566027315936.22/warc/CC-MAIN-20190821110541-20190821132541-00011.warc.gz"}