import java.util.Arrays; import java.util.Random; /** * This class implements a Dynamic Programming solution for the Skiing Problem * @author YOUR NAMES HERE * */ public class Skiing { // All measurements are given in inches private static final int MAX_HEIGHT = 77; private static final int MIN_HEIGHT = 61; // Feel free to change these values as long as NUM_SKIS > NUM_SKIERS private static final int NUM_SKIS = 5; private static final int NUM_SKIERS = 3; // These will contain the actual human and ski lengths private static int[] skiHeights; private static int[] skierHeights; /** * Randomly populates the skier and ski arrays with realistic * human heights and ski lengths */ private static void populateArrays(){ Random rng = new Random(); for(int i = 0; i < skierHeights.length; i++){ skierHeights[i] = rng.nextInt(MAX_HEIGHT-MIN_HEIGHT + 1) + MIN_HEIGHT; } for(int i = 0; i < skiHeights.length; i++){ skiHeights[i] = rng.nextInt(MAX_HEIGHT-MIN_HEIGHT + 1) + MIN_HEIGHT; } } /** * Returns an optimal solution to an instance of the Skiing Problem. * @param assignments An array whose length is the number of skiers. The ith entry * in the array is the ski assignment for person i. */ public static void computeSolution(int[] assignments){ } /** * Once you're done, you can run this main method to test your code. */ public static void main(String[] args){ skiHeights = new int[NUM_SKIS]; skierHeights = new int[NUM_SKIERS]; populateArrays(); // Note: sorting is crucial for this problem...why is that? Arrays.sort(skiHeights); Arrays.sort(skierHeights); int[] assignments = new int[NUM_SKIERS]; computeSolution(assignments); System.out.println("The optimal ski assignment is: "); System.out.println(Arrays.toString(assignments)); } }