100% faster and simple to understand c++ dp solution
\nint countSubstrings(string s, string t) {\n        int m = s.length();\n        int n = t.length();\n        int dp[m+1][n+1][2];\n        for(int i=0; i<=m; 
```\nint countSubstrings(string s, string t) {\n        int m = s.length();\n        int n = t.length();\n        int dp[m+1][n+1][2];\n        for(int i=0; i<=m; i++)\n        {\n            for(int j=0; j<=n; j++)\n            {\n                //dp[i][j][0] denotes number of substring ending at i that matches with\n                //substrings ending at j\n                dp[i][j][0]=0; \n                //dp[i][j][1] denotes number of substrings ending at i that differs from\n                //substrings ending at j by one character\n                dp[i][j][1]=0;\n            }\n        }\n        int out = 0;\n        for(int i=1; i<=m; i++)\n        {\n            for(int j=1; j<=n; j++)\n            {\n                //If chars at i and j matches then either continue previous one\n                //or just take the current one(new string)\n                dp[i][j][0]= (s[i-1]==t[j-1])?dp[i-1][j-1][0]+1:0;\n                //If chars at i and j matches then continue with previous one\n                //else just take the previous matching substrings and increase it by 1\n                dp[i][j][1]= (s[i-1]==t[j-1])?dp[i-1][j-1][1]:dp[i-1][j-1][0]+1;\n                out += dp[i][j][1];\n            }\n        }\n        return out;\n    }\n```
['Dynamic Programming']