//first set up the last two cells, then dp forward
class Solution {
public:
int numDecodings(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(s.size()==0)
return 0;
int size=s.size();
//vector<int> ways(size+1,0);
vector<int> ways(size+1);
ways[size]=1;
ways[size-1]=s[size-1]=='0'?0:1;
for(int i=size-2;i>=0;--i){
if(s[i]=='0')
ways[i]=0;
else {
ways[i]=ways[i+1];
if(s[i]=='1'||(s[i]=='0'&&s[i+1]!='0')||(s[i]=='2'&&s[i+1]<='6')){
ways[i]+=ways[i+2];
}
}
}
return ways[0];
}
};