C++ | Top-Down DP | Recursion with Memoization
\nclass Solution {\npublic:\n    int mod=1e9+7;\n    int helper(string& s,int idx,vector<int>& dp){\n        if(idx==s.size()){\n            return 1;\n        
```\nclass Solution {\npublic:\n    int mod=1e9+7;\n    int helper(string& s,int idx,vector<int>& dp){\n        if(idx==s.size()){\n            return 1;\n        }\n        if(dp[idx]!=-1){\n            return dp[idx];\n        }\n        int n=s.size();\n        int res=0;\n        res+=helper(s,idx+1,dp);\n        if(idx+1<n and s[idx+1]==s[idx]){\n            res+=helper(s,idx+2,dp);\n            res%=mod;\n        }\n        if(idx+2<n and s[idx+1]==s[idx] and s[idx+2]==s[idx]){\n            res+=helper(s,idx+3,dp);\n            res%=mod;\n        }\n        if((s[idx]==\'7\' or s[idx]==\'9\') and idx+3<n and s[idx+1]==s[idx] and s[idx+2]==s[idx] and s[idx+3]==s[idx]){\n            res+=helper(s,idx+4,dp);\n            res%=mod;\n        }\n        return dp[idx]=res;\n    }\n    int countTexts(string s) {\n        vector<int> dp(s.size(),-1);\n        return helper(s,0,dp);\n    }\n};\n```
[]