1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
zhenek [66]
3 years ago
14

/* Function findBestVacation * duration: number of vacation days * prefs: prefs[k] indicates the rate specified for game k * pla

n: array with 366 positions with the sequence of games * to be played over the year. In other words, * plan[k] indicates the game planned for day k (1

Engineering
1 answer:
alexira [117]3 years ago
3 0

Answer:

This is the C++ code for the above problem:

#include<bits/stdc++.h>

using namespace std;

int computeFunLevel(int start, int duration, int prefs[], int ngames, int plan[]) {

if(start + duration > 365) { //this is to check wether duration is more than total no. of vaccation days

return -1;

}

int funLevel = 0;

for(int i=start; i<start+duration; i++) { //this loop runs from starting point till

//start + duration to sum all the funlevel in plan.

funLevel = funLevel + prefs[plan[i]];

}

return funLevel;

}

int findBestVacation(int duration, int prefs[], int ngames, int plan[]) {

int max = 0, index = 0, sum = 0 ;

for(int i=1; i<11; i++){ //this loop is to run through whole plan arry

sum = 0; //sum is initialized with zero for every call in plan ,

//in this case loop should run to 366,but for example it is 11

//as my size of plan array is 11

for(int j=0; j<duration; j++) { // this loop is for that index to index+duration to calc

//fun from that index

sum = sum + prefs[plan[i]];

}

if(sum>max) { //this is to check max funlevel and update the index from which max fun can be achieved

max = sum;

index = i;

}

}

return index;

}

int main() {

int ngames = 5;

int prefs[] = { 1,2,0,5,2 };

int plan[] = { 0,2,0,3,3,4,0,1,2,3,3 };

int start = 1;

int duration = 4;

cout << computeFunLevel(start, duration, prefs, ngames, plan) << endl;

cout << computeFunLevel(start, 555, prefs, ngames, plan) << endl;

cout << findBestVacation(4, prefs, ngames, plan) << endl;

}

The screen of the program is given below.

You might be interested in
Pouring molten aluminum into a mold and allowing it to cool forms?
neonofarm [45]

Answer:it forms a molten mold that makes it hard to be able to smash something into it then make something like a key

Explanation:

7 0
3 years ago
What is the primary function of NCEES?
joja [24]
National Council of Examiners for engineering and surveying a nonprofit organization
7 0
4 years ago
Who want to 1v1 lol unblocked games 76 with me
Ede4ka [16]

Answer:

what's that??

Explanation:

7 0
4 years ago
Read 2 more answers
Many jacks use hydraulic power. True or False
34kurt

Answer:true

Explanation:

7 0
3 years ago
A event that would cause an earthquake.
alexandr402 [8]
Tectonic plates shifting
4 0
3 years ago
Other questions:
  • Who does the narrator blame for the loss of her job as editor-in-chief? <br> see if i care readworks
    8·2 answers
  • What is 29*69+98-78/36=
    9·2 answers
  • A non-entrepreneurship, work-based, agricultural type of SAE, in which a student learns and gains skills in a paid or unpaid pos
    15·1 answer
  • What is the horizontal distance from Point A to toe of slope?
    12·1 answer
  • A(n) ____ is an object setting used to control the visible display of objects.
    15·1 answer
  • A horse pulls a cart along a road with a force of 550 lbs. If the horse does 2,674,100 ftlbs of work by the time it stops, how f
    9·2 answers
  • ANSWER ASAP<br> What is the point system?<br> this is for driving
    8·1 answer
  • To understand the concept of moment of a force and how to calculate it using a scalar formulation.
    9·1 answer
  • The ruler game, HELPPPP PLS
    11·2 answers
  • ANSWER QUICK
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!