Implement an Java ElectionSimulator class that can compute the minimum number of popular votes needed to win the Electoral College given the turnout during an election year.
1) ElectionSimulator(List<State> states)ElectionSimulator for the given list of states.2) Set<State> simulate()electoralVote threshold and the current index into the list of states. Then, solve the following optimization problem: “What is the set of states that minimizes the popular vote while satisfying the electoralVote threshold and using only states starting at the given index into the list of all states?”Use the provided Arguments class to memoize (save) the solution to each subproblem by mapping the subproblem arguments to the set of states. If we’ve solved the subproblem before, then return the combination saved in the map.
- In the constructor, add a field to keep track of a new
Map<Arguments, Set<State>>. - In the recursive case, save the final solution to the current subproblem before returning the result.
- In the base case, if the solution to the current subproblem was saved earlier, return the saved solution.


0 comments