public static int numDistinct(String S, String T) {
		int m=S.length(), n=T.length();
		int[][] t=new int[m+1][n+1];
		for (int i=0;i<=m;++i)
			t[i][0]=1;
		for (int i=1;i<=m;++i) {
			for (int j=1;j<=n;++j)
				t[i][j]=(S.charAt(i-1)==T.charAt(j-1)?t[i-1][j-1]:0)+t[i-1][j];
		}
		return t[m][n];
	}