Question: Exercise 2 (Dynamic Programming (35 points)) As described in our previous assignment, the teach- ing staff of Comp251 is getting ready to come back to


Exercise 2 (Dynamic Programming (35 points)) As described in our previous assignment, the teach- ing staff of Comp251 is getting ready to come back to in-person classes. Please remember that Comp251 lectures will happen then in the McGill Gym (because space constrains). Knowing how fun it is to have in-person midterms (is not it?), we are already planning our first exam. Each student will take the exam once at the time. For the exam, we will arrange a row on N chairs, numbered 1 to N. The student will be seated initially in the first chair and can jump to other chairs. The student's first jump must be to the second chair. Each subsequent jump must satisfy the following two constraints: If the jump is in the forward direction, it must be one square longer than the preceding jump. If the jump is in the backward direction, it must be exactly the same length as the preceding jump. Every time that the student jump to sit in a chair, I will deduct some marks. The exam will be over once the student sit down in the last chair (i.e., the N chair). It is in the interest of the student to get from the first chair (i.e., chair 1) to the last chair (i.e., chair N) losing as few marks as possible. For this question of the assignment, you will complete the function lost_marks which determines the smallest total marks lost by the student in the attempt to get to the chair N. The signature of the function lost_marks in the java file Midterm.java is as follows. public static int lost_marks (int[] penalization) { //To Do => Please start coding your solution here } The function lost_marks gets as a parameter an array of integers called penalization, which stores the marks that we will deduct each time that the student sits in that specific chair. Please notice that penalization[0] represents the lost marks for the first chair (chair 1) and penalization (N-1] represents the lost marks for the last chair (chair N), in general, penalization[i] represents the lost marks for the i-th chair. The number of chairs N will be in the following limits 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
