This problem uses dynamic planning to do, but at the beginning of the time has been timed out, I thought it is the cause of other places, but how to change the problem (code below) Later, I found that I do not have a dynamic planning ah, is normal recursion, no wonder it will time out The difference between dynamic programming and normal recursion is that you don't have to repeat the calculations.!!!!!
classSolution { Public: intNumdecodings (strings) {intlen=s.size (); if(len==0|| s[0]=='0') return 0; intnum; intRes; if(len==1) Num=s[0]-'0'; Else if(len==2) Num=Ten* (s[0]-'0') +s[1]-'0'; if(num==0) return 0; Else if(num<=Ten) return 1; Else if(num>Ten&&num<= -) return 2; Else if(num> -&&num<= About) return 1; Res=max (Numdecodings (S.substr (0,1)) +numdecodings (S.substr (1, Len)), Numdecodings (S.substr (0,2)) +numdecodings (S.substr (2, Len)); returnRes; }};
http://blog.csdn.net/worldwindjp/article/details/19938131
Decode Ways (to be done)