public int numDistinct(String S, String T) {
    	int tbl[][] = new int[T.length() + 1][S.length() + 1];
    	for (int i = 0; i <= S.length(); i++)
    		tbl[0][i] = 1;
    	for (int i = 1; i <= T.length(); i++)
    		tbl[i][0] = 0;
    	
    	for (int i = 1; i <= T.length(); i++)
    		for (int j = 1; j <= S.length(); j++)
    		{
    			tbl[i][j] = tbl[i][j - 1]; 
    			if (T.charAt(i - 1) == S.charAt(j - 1))
    				tbl[i][j] += tbl[i - 1][j - 1];
    		}
    	return tbl[T.length()][S.length()];
    }