memoization to tablulation||c++
\nclass Solution {\npublic:   \n    int m=1e9+7;\n    vector<int> arr={0,0,3,3,3,3,3,4,3,4}; \n    int dp[100003];\n    int solve(string &s,int i){\n        if(
```\nclass Solution {\npublic:   \n    int m=1e9+7;\n    vector<int> arr={0,0,3,3,3,3,3,4,3,4}; \n    int dp[100003];\n    int solve(string &s,int i){\n        if(i==s.length()) return 1;\n        if(dp[i]!=-1) return dp[i];\n        long long ans=0;\n        int j=0; \n        ans=(ans%m+solve(s,i+1)%m)%m; \n        for(j=i+1;j<s.length()&&j<i+arr[s[i]-\'0\'];j++){ \n            if(s[j]!=s[j-1]) break;\n            ans=(ans%m+solve(s,j+1)%m)%m;\n        } \n        return dp[i]=ans;\n    }\n    int countTexts(string s) {  \n        memset(dp,-1,sizeof dp);\n      return solve(s,0);\n    }\n};\n``` \n**CONVERTING IT TO TABULATION (credit-striver)** \nfollowing steps involve in coverting memoization into tabulation\n1.Declare same size storage and intialise base case.\n2.Observe changing paremeter (i)  i->0,1,2,3,4,5 \n3.write down the loop of changing parameter in reverse order.\n4.Copy the recusion. \n\n```\nclass Solution {\npublic:    \n    //tabulation\n    int m=1e9+7;\n    vector<int> arr={0,0,3,3,3,3,3,4,3,4}; \n    int countTexts(string s) {  \n      vector<int> dp(s.length()+1);\n      dp[s.length()]=1; //step1\n      for(int i=s.length()-1;i>=0;i--){ //step 2 and 3 \n\t  //step 4\n        long long ans=0;\n        int j=0; \n        ans=(ans%m+dp[i+1]%m)%m; \n        for(j=i+1;j<s.length()&&j<i+arr[s[i]-\'0\'];j++){ \n            if(s[j]!=s[j-1]) break;\n            ans=(ans%m+dp[j+1]%m)%m;\n        } \n        dp[i]=ans;\n      }\n      return dp[0];\n    }\n};\n```
['Dynamic Programming']