Java Dp
\nclass Solution {\n    public int countSubstrings(String s, String t) {\n        int ans=0,n=s.length(),m=t.length();\n        int dp[][]=new int[n+1][m+1];\n 
```\nclass Solution {\n    public int countSubstrings(String s, String t) {\n        int ans=0,n=s.length(),m=t.length();\n        int dp[][]=new int[n+1][m+1];\n        int tp[][]=new int[n+1][m+1];\n        for(int i=n-1;i>=0;i--)\n        {\n            for(int j=m-1;j>=0;j--)\n            {\n                if(s.charAt(i)==t.charAt(j))\n                {\n                    dp[i][j]=dp[i+1][j+1]+1;\n                    tp[i][j]=tp[i+1][j+1];\n                }\n                else\n                {\n                    tp[i][j]=dp[i+1][j+1]+1;\n                }\n                ans=ans+tp[i][j];\n            }\n        }\n        return ans;\n    }\n}\n```
[]