C++ Recursion  + Memoization + KMP
```\nclass Solution {\npublic:\n    int mod = 1000000007;\n    vectorlps;\n    int m, n;\n    string s1, s2, evil;\n    int dp[501][51][2][2];\n    int solve(in
```\nclass Solution {\npublic:\n    int mod = 1000000007;\n    vector<int>lps;\n    int m, n;\n    string s1, s2, evil;\n    int dp[501][51][2][2];\n    int solve(int i, int matched, int left, int right){\n        if(matched == m) return 0;\n        if(i == n) return 1;\n        if(dp[i][matched][left][right] != -1) return dp[i][matched][left][right];\n        char from = left ? s1[i] : \'a\';\n        char to = right ? s2[i] : \'z\';\n        int res = 0;\n        for(char c = from; c <= to; c++){\n            int j = matched;\n            while(j > 0 && evil[j] != c) j = lps[j - 1];\n            if(c == evil[j]) j++;\n            res += solve(i + 1, j, left && (c == from) , right && (c == to));\n            res %= mod;\n        }\n        cout<<res<<endl;\n        return dp[i][matched][left][right] = res;\n    }\n    int findGoodStrings(int n, string s1, string s2, string evil) {\n        this->n = n;\n        this->s1 = s1, this->s2 = s2, this->evil = evil;\n        m = evil.size();\n        memset(dp, -1, sizeof(dp));\n        lps.resize(m, 0);\n        int i = 1, j = 0;\n        while(i < m){\n            if(evil[i] == evil[j]){\n                lps[i++] = ++j;\n            }\n            else{\n                if(j != 0)\n                    j = lps[j - 1];\n                else i++;\n            }\n        }\n        int ans = solve(0, 0, 1, 1);\n        return ans;\n    }\n};
[]