Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- const int maxn = 255;
- const int INF = 2e9;
- string s;
- int n;
- int dp[maxn];
- int rec(int at) {
- if(at >= n) {
- return 1;
- }
- if(dp[at] != -1) {
- return dp[at];
- }
- int res = 0;
- if(s[at] != '0') {
- res += rec(at + 1);
- }
- if(at + 1 < n) {
- int number = (s[at] - '0') * 10 + (s[at + 1] - '0');
- if(s[at] != '0' and number <= 26) {
- res += rec(at + 2);
- }
- }
- dp[at] = res;
- return res;
- }
- int main() {
- cin >> s;
- n = (int) s.size();
- memset(dp, -1, sizeof dp);
- cout << rec(0) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement