ways[0] = 1 (empty t). For each character of s, update j from m down to 1 so each s character is used once per alignment.
Approach 1
class Solution {
public int numDistinct(String s, String t) {
int m = t.length();
long[] ways = new long[m + 1];
ways[0] = 1;
for (int i = 0; i < s.length(); i++)
for (int j = m; j >= 1; j--)
if (s.charAt(i) == t.charAt(j - 1)) ways[j] += ways[j - 1];
return (int) ways[m];
}
}