Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this problem quickly In Java or python or c++. Help me someone!!!!!!!!!! Your goal for this challenge will be to determine

I need help with this problem quickly In Java or python or c++. Help me someone!!!!!!!!!!

Your goal for this challenge will be to determine the best path for moving across a matrix of integers. For each matrix of size n, you will start in the top-left corner (0, 0) and must end in the bottom-right corner (n, n) by moving only down or to the right (you cannot move up or to the left). The value in each cell of the matrix represents the number of points you get from visiting the cell. Your algorithm should find the path that results in the maximum possible number of points while successfully crossing the matrix. In the case of a tie, your algorithm should prefer the path that would move to the right before it would move down. Input: A square matrix of integers. Each row will be separated by a semicolon; each column within a row will be separated by a space. Examples:

0,2;4,3 => | 0 | 2 | | 4 | 3 | 
1,2,3;6,5,4;8,-7,9 => | 1 | 2 | 3 | | 6 | 5 | 4 | | 8 | -7 | 9 | 

Output

A comma separated list of your moves across the matrix. Each move should be specified by:

d => move down r => move right 

Examples of correct solutions to the matrices listed above:

d,r 
d,r,r,d 

Test 1

Test Input

Download Test Input

-1,-2,-3;-4,-5,-6;-7,-8,-9 

Expected Output

Download Test Output

r,r,d,d 

Test 2

Test Input

Download Test Input

1,2,3;6,5,4;8,-7,9 

Expected Output

Download Test Output

d,r,r,d 

Test 3

Test Input

Download Test Input

0,2;4,3 

Expected Output

Download Test Output

d,r 

Running Test 1... failed!

Test 1 Input

-1,-2,-3;-4,-5,-6;-7,-8,-9 

Expected Output

r,r,d,d 

Your Output

-1,-2,-3;-4,-5,-6;-7,-8,-9 

End Test Case Output Tab Content

Running Test 2... failed!

Test 2 Input

1,2,3;6,5,4;8,-7,9 

Expected Output

d,r,r,d 

Your Output

1,2,3;6,5,4;8,-7,9 

End Test Case Output Tab Content

Running Test 3... failed!

Test 3 Input

0,2;4,3 

Expected Output

d,r 

Your Output

0,2;4,3 

My work

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets;

public class Main { /** * Iterate through each line of input. */ public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

What language is accepted by the DFA? a 93 b b a b a a 90 91 q2

Answered: 1 week ago