static double house_majority_helper(double[] prob, int r, int n,
			double[][] P) {
		if (r > n) {
			return 0.0; // base case: not enough Republicans.
		} else if (r == 0 && n == 0) {
			return 1.0; // base case.
		} else if (r < 0) {
			return 0.0;
		}

		if (P[r][n] == -1.0) {
			P[r][n] = house_majority_helper(prob, r - 1, n - 1, P) * prob[n - 1] 
					+ house_majority_helper(prob, r, n - 1, P) * (1.0 - prob[n - 1]);
		}
		return P[r][n];
	}