public static int countWaysOfChange(int[] S, int n) {
		if (n < 0) {
			return 0;
		}
		
		if (n == 0) {
			return 1;
		}
		
		int m = S.length;
		int[][] counts = new int[m + 1][n + 1];
		
		for (int j = 0; j <= n; j++) {
			counts[0][j] = 0;
		}
		
		for (int i = 0; i <= m; i++) {
			counts[i][0] = 1;
		}
		
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				int count = 0;
				
				count += counts[i - 1][j];
				
				if (j - S[i - 1] >= 0) {
					count += counts[i][j - S[i - 1]];
				}
				
				counts[i][j] = count;
			}
		}
		
		return counts[m][n];
	}