Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include int MaxDriverPay(int n, int* L, int* H) { return 0; } main.cpp #include using namespace std; #include Q2.cpp int main(){ int L[]={1,2,1,4,5,17,3,15,10,13}; int
#include
int MaxDriverPay(int n, int* L, int* H) { return 0; }
main.cpp #include
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
// the 9 was given to you in MaxDriverPay(9,L,H) assuming L and H are zero-based arrays. So 9 was referencing the 10th element." // correct answer should be 193 return 0; }
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 driver's 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 Output As a result, your function should return the maximum payment the driver can get based on the given input Example 1: N=4011111111111111111111111111111111111111113333333333333333333333333333333333333333 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 (203)+1 light load at the end =61 Example 2: N=3525756 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 totalStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started