Question: (c++) solve it using dynamic programing, please don't copy paste from other solutions because they don't work. Assume you want to build a program to

(c++)

solve it using dynamic programing, please don't copy paste from other solutions because they don't work.

Assume you want to build a program to help drivers maximize their income based on the loads they carry on a daily basis. Consider that we have n days of data where each day i allows a truck to carry a load. The truck driver has two choices: a light or a heavy load. The truck driver will get paid the amount of Li in case the driver selects a light load on day i. Alternatively, the driver will get paid Hi in case of selecting a heavy load on day i. The driver cannot carry more than one load per day. Also, if the driver selects to carry a heavy load, the driver is not allowed to carry any load the day before. Your goal is to maximize the drivers income.

Write the MaxDriverPay(int N, int* L, int * H) function which takes three inputs:

N (1N) which represents the number of days

L which represents an array of N values where each Li value represents the payment of day i in case light load is selected that day

H which represents an array of N values where each Hi value represents the payment of day i in case heavy load is selected that day

Day 1 2 3 .. n

Light load L1 L2 L3 .. Ln

Heavy load H1 H2 H3 .. Hn

Output

As a result, your function should return the maximum payment the driver can get based on the given input

Example 1:

N=40

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

Result is 61

Explanation:

The best is to start with a high load, then you will carry a high load every other day, you will have 20 heavy loads (20*3) + 1 light load at the end = 61

Example 2:

N=3

5 5 5

2 7 6

Result is 15

Explanation:

Better to pick all light loads, the total will be 15, because if we pick any of the heavy loads, we can use the load from the day before which means we cannot be higher than 15 total

main code:

int main(){ int L[]={1,2,1, 4, 5,17,3,15,10,13}; int H[]={2,5,11,110,26,20,6,25,32,31}; cout <

(make sure that the code works for the main function and gives the correct answer as it is in the main function and for all cases)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!