Question

Use C++. The game of “Jump It” consists of a board with n positive integers in...

Use C++. The game of “Jump It” consists of a board with n positive integers in a row, except for the first
column, which always contains zero. These numbers represent the cost to enter each column.
Here is a sample game board where n is 6:


0 3 80 6 57 10


The object of the game is to move from the first column to the last column with the lowest total
cost.
The number in each column represents the cost to enter that column. You always start the game
in the first column and have two types of moves. You can either move to the adjacent column or
jump over the adjacent column to land two columns over. The cost of a game is the sum of the
costs of the visited columns.
In the board shown above, there are several ways to get to the end. Starting in the first column,
our cost so far is 0. We could jump to 80, then jump to 57, and then move to 10 for a total cost
of 80 + 57 + 10 = 147. However, a cheaper path would be to move to 3, jump to 6, then jump to
10, for a total cost of 3 + 6 + 10 = 19.
Write a recursive function that solves this problem and returns the lowest cost of a game board
represented and passed as an array.
Note: your function shouldn’t output the actual sequence of jumps, only the lowest cost of this
sequence.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*Algo: In each step we have two options either we can choose
adjacent column or next to adjacent column .
In both the case which value leads to minimum jump cost that will be selected.
So, recursion would be
R(x)=arr[x]+min(R(x+1)+R(x+2)) where arr: array of jump cost
R: Recursion equation */

Solution:

#include <iostream>
using namespace std;
int minJumpCost(int arr[],int start,int n)
{
if(start==n-1) //if we reached at destination
return arr[start];
if(start>=n) //out of destination
return INT_MAX;
//either select adjacent or next to adjacent
return arr[start]+min(minJumpCost(arr,start+1,n),minJumpCost(arr,start+2,n));
}
int main()
{
int n;//size of array
cout<<"Enter Size of array: ";
cin>>n;
int arr[n]; //jump cost array
cout<<"Enter jump cost:";
for(int i=0;i<n;i++)
cin>>arr[i];
cout<<"Minimum jump cost: "<<minJumpCost(arr,0,n);
return 0;
}

Output

Add a comment
Know the answer?
Add Answer to:
Use C++. The game of “Jump It” consists of a board with n positive integers in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The game of “Jump It” consists of a board with n positive integers in a row,...

    The game of “Jump It” consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board where n is 6: 0 3 80 6 57 10 The object of the game is to move from the first column to the last column with the lowest total cost. The number in each column represents the cost to...

  • Write a class named FBoard for playing a game... PLEASE USE C++ PLEASE DO NOT USE "THIS -->". NOT ALLOWED PLE...

    Write a class named FBoard for playing a game... PLEASE USE C++ PLEASE DO NOT USE "THIS -->". NOT ALLOWED PLEASE PROVIDE COMMENTS AND OUTPUT! Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • (C++) Please create a tic tac toe game. Must write a Player class to store each...

    (C++) Please create a tic tac toe game. Must write a Player class to store each players’ information (name and score) and to update their information (increase their score if appropriate) and to retrieve their information (name and score).The players must be called by name during the game. The turns alternate starting with player 1 in the first move of round 1. Whoever plays last in a round will play second in the next round (assuming there is one).The rows...

  • In C++. Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o i...

    In C++. Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member called gameState that holds one of the following values: X_WON, O_WON, or UNFINISHED - use an enum type for this, not string (the...

  • IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. •...

    IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. • Declare a global enum variable that will support 10 values – each representing an ant colony {A, B, C, D, E, F, G, H, I, J}. • In the main function, o Declare a 2-dimensional array of size the global integer constant, SIZE. The number of rows and columns should be equal to SIZE, which would make this a square matrix. This array will...

  • C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an...

    C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an elimination dice game. It can be played by any number of players, but it is ideal to have three or more players. Wild, Wild, West! Requires the use of two dice. At the start of the game, each player receives a paper that will track the number of lives that player has. Each player starts the game with 6 lives. In the first round,...

  • can someone help me with this C++ problem write your game() function and 3+ functions that...

    can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...

  • Please develop the following code using C programming and using the specific functions, instructi...

    Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...

  • For this assignment, your job is to create a simple game called Opoly. The objectives of...

    For this assignment, your job is to create a simple game called Opoly. The objectives of this assignment are to: Break down a problem into smaller, easier problems. Write Java methods that call upon other methods to accomplish tasks. Use a seed value to generate random a sequence of random numbers. Learn the coding practice of writing methods that perform a specific task. Opoly works this way: The board is a circular track of variable length (the user determines the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT