Skip to content

Instantly share code, notes, and snippets.

@mhmoodlan
Created September 4, 2017 10:02
Show Gist options
  • Select an option

  • Save mhmoodlan/88a4848ec7ca74488429ed2c93b4d4f9 to your computer and use it in GitHub Desktop.

Select an option

Save mhmoodlan/88a4848ec7ca74488429ed2c93b4d4f9 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define ll long long
#define sz(v) ((int) ((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define lp(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep(i, v) for(int i = 0; i < sz(v); ++i)
using namespace std;
const int MAX = 5005;
const int OO = 1e9;
string s;
int n;
ll cache[MAX];
ll acode(int i) {
if(i == n)
return 1;
ll &ret = cache[i];
if(ret != -1)
return ret;
ret = 0;
if(s[i] != '0') {
ret += acode(i+1);
if(i!=n-1) {
int x = (s[i]+'\0'-48) * 10;
int y = s[i+1]+'\0'-48;
//cout << x+y << endl;
if(x+y <= 26)
ret += acode(i+2);
}
}
return ret;
}
int main() {
while(cin>>s && s != "0") {
clr(cache, -1);
n = s.length();
cout << acode(0) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment