[C++] For everyone who are scared of DP like me.
So I experimented with 2, 22, 222 and realised that for 2222 the answer is the sum of previous 3 and this goes on.\n Now after doing this I was stuck thinking a
* So I experimented with `2`, `22`, `222` and realised that for `2222` the answer is the sum of previous 3 and this goes on.\n* Now after doing this I was stuck thinking all the numbers have 3 letters but for `7` and `9`, the story is different since they have 4 letters.\n* So I experimented **again** with `9`, `99`, `999`, `9999` and realised that for `99999` the answer is the sum of previous 4 and this goes on.\n* And Boom **AC**.\n\n`//Experiment part`\nWhy we do `dp[n] = dp[n-1] + dp[n-2] + dp[n-3]` ?\nBecause we have 3 options,\nLets take example of `22222`.\n\n`22222` = `2|2222` + `22|222` + `222|22`.\nBasically we select the first (1-3) numbers and rest are already calculated.\n**Note:** we can\'t have a combination like this `2222|2` since four 2\'s don\'t make any combination(in case of 2 but in case of 7 and 9 its does and therefore the summation goes till `dp[n-4]` there).\n\n```\nconst int mod = 1e9 + 7;\nconst int mxx = 1e5 + 1;\n#define ll long long\nclass Solution {\npublic:\n    vector<int> a, b;\n    \n    Solution()\n    {\n        a.resize(mxx, 0);\n        a[1] = 1;\n        a[2] = 2;\n        a[3] = 4;\n        \n        for(int i=4; i<=1e5; i++)\n        {\n            a[i] = ((a[i-1] + a[i-2]) % mod + a[i-3]) % mod;\n        }\n        \n        b.resize(mxx, 0);\n        b[1] = 1;\n        b[2] = 2;\n        b[3] = 4;\n        b[4] = 8;\n        \n        for(int i=5; i<=1e5; i++)\n        {\n            b[i] = ((((b[i-1] + b[i-2]) % mod + b[i-3]) % mod) + b[i-4]) % mod;\n        }\n    }\n    \n    int countTexts(string s) {\n        int n = s.size();\n        int ans = 1;\n        \n        int cnt = 1;\n        int i = 0;\n        while(i+1 < n)\n        {\n            while(i+1 < n && s[i] == s[i+1]) \n            {\n                cnt++;\n                i++;\n            }\n            // cout << a[cnt] << " ";\n            if(s[i] != \'7\' && s[i] != \'9\')\n                ans = ((ll)ans * (ll)a[cnt]) % mod;\n            else\n                ans = ((ll)ans * (ll)b[cnt]) % mod;\n            \n            cnt = 1;\n            i++;\n        }\n        return ans;\n    }\n};\n```\n\nActually the `experimented` part is something which is really hard for me explain. Do some experiment on your own and maybe it will click.
['C', 'C++']