-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacode.cpp
More file actions
37 lines (36 loc) · 705 Bytes
/
acode.cpp
File metadata and controls
37 lines (36 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define mp make_pair
typedef long long ll;
int dp[5050];
int acode(string &s,int i,int n) {
if(s[i]=='0')
return 0;
if(i==n||i==n-1)
return 1;
if(dp[i]!=-1)
return dp[i];
int ans=acode(s,i+1,n);
int a=s[i]-'0',b=s[i+1]-'0';
int c=a*10+b;
if(c<=26&&c>9) {
ans+=acode(s,i+2,n);
}
return dp[i]=ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin>>s;
while(s!="0") {
memset(dp,-1,sizeof(dp));
int n=s.size();
int ans=acode(s,0,n);
cout<<ans<<"\n";
cin>>s;
}
return 0;
}