本文主要是介绍算法:解码方法(动态规划)—— decode-ways(Dynamic programming),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
problem:
A string “s” is consisted of number characters. If thesubstring value of one or two adjacent characters in “s” is between 1 and 26,the substring can be converted to an alphabet. The rule is set as follows: “1”is converted to “A”, “2” to “B”, “3” to “C” ... and ”26” to “Z”. Please findout how many different results can string “s” be converted to.
(there is no corresponding letter to “0”)
Example:
Input: s=”123”
The results canbe: ”ABC”, “LC”, “AW” (“23” to “W”,“12” to “L”)
Output: 3
Understandingand solving ideas
This problem isa one-dimensional problem, under normal circumstances is better to solve theproblem is that it is a reverse order of the problem, from the back push, dp[i] from the i-bit to the last one can be converted to th
这篇关于算法:解码方法(动态规划)—— decode-ways(Dynamic programming)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!