ricky123ghfghfhg

coorect code\

May 27th, 2023
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | Source Code | 0 0
  1.    #define ll long long int
  2.     #define mod (int)(1e9+7)
  3.     int f(int ind,string& str,int n,vector<ll>& dp)
  4.     {
  5.          if(ind==n) return 1;
  6.          
  7.          if(dp[ind]!=-1) return dp[ind];
  8.          
  9.          int onech=0,twoch=0;
  10.          if(str[ind]>='1' && str[ind]<='9')
  11.          {
  12.              onech=f(ind+1,str,n,dp);
  13.          }
  14.          string temp=str.substr(ind,2);
  15.          if(ind<n-1 && temp>="10" && temp<="26")
  16.          {
  17.              twoch=f(ind+2,str,n,dp);
  18.          }
  19.          return dp[ind]=(onech+twoch)%mod;
  20.     }
  21.     int CountWays(string str){
  22.         int n=str.length();
  23.         vector<ll> dp(n,-1);
  24.         return f(0,str,n,dp);
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment