```
public class Solution {
public int numDistinct(String s, String t) {
int M = s.length();
int N = t.length();
int[] dp = new int[N + 1];
dp[0] = 1;
for (int j = 1; j <= M; j++) {
for (int i = N; i >= 1; i--) {
if (s.charAt(j - 1) == t.charAt(i - 1)) {
dp[i] += dp[i - 1];
}
}
}
return dp[N];
}
}
```