c++ code | memoization
\nclass Solution {\npublic:\n    int dp[105][105];\n    \n    int func(string &s,string &t,int i,int j,int status){\n        if (i<0 || j<0){\n            retur
```\nclass Solution {\npublic:\n    int dp[105][105];\n    \n    int func(string &s,string &t,int i,int j,int status){\n        if (i<0 || j<0){\n            return 0;\n        }\n        \n        if (dp[i][j]!=-1){\n            return dp[i][j];\n        }\n        \n        int val=0;\n        \n        if (status==0){\n            if (s[i]==t[j]){\n                val=func(s,t,i-1,j-1,0);\n            }\n            else{\n                val=1+func(s,t,i-1,j-1,1);\n            }\n        }\n        else{\n            if (s[i]==t[j]){\n                val=1+func(s,t,i-1,j-1,1);\n            }\n            else{\n                val=0;\n            }\n        }\n        \n     return dp[i][j]=val;\n    }\n    \n    int countSubstrings(string s, string t) {\n        int ans=0;\n        \n        \n        for (int i=0; i<s.length(); i++){\n            for (int j=0; j<t.length(); j++){\n                memset(dp,-1,sizeof(dp));\n               ans+=func(s,t,i,j,0);\n            }\n        } \n        \n     return ans;\n    }\n};\n```
[]