Advertisement
Josif_tepe

Untitled

Oct 20th, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. string s;
  5. int dp[255];
  6. int kod(int i) {
  7.     if(i >= s.size()) {
  8.         return 1;
  9.     }
  10.     if(dp[i] != -1) {
  11.         return dp[i];
  12.     }
  13.     int result = 0;
  14.     if(i + 1 < s.size() and s[i] != '0') {
  15.         int broj = (s[i] - '0') * 10 + (s[i + 1] - '0');
  16.         if(broj <= 26) {
  17.             result += kod(i + 2);
  18.         }
  19.     }
  20.     if(s[i] != '0') {
  21.         result += kod(i + 1);
  22.     }
  23.     dp[i] = result;
  24.     return result;
  25. }
  26. int main() {
  27.     cin >> s;
  28.     for(int i = 0; i < 251; i++) {
  29.         dp[i] = -1;
  30.     }
  31.     cout << kod(0) << endl;
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement