subject

Written in Java Design a recursive algorithm to find the longest increasing sequence of numbers in a rectangular grid. For example, if the grid contains 97 47 56 36 35 57 41 13 89 36 98 75 25 45 26 17 then the longest increasing sequence of numbers is the sequence of length eight consisting of 17, 26, 36, 41, 47, 56, 57, 97. Design an algorithm that solves the same problem but allows for non-decreasing sequences; thus there may be duplicates in the increasing sequence. Can i get help cleaning this up. it needs to be able to allow duplicates
Java Code
import java. util. Stack;
public class {
private static void (int[][] grid, int r, int c) {
int[][] g = new int[r][c];
for (int a = 0; a < r; a++) {
for (int b = 0; b < c; b++) {
g[a][b] = 1;
}
}
int maxLen = -1;
int idx1 = -1;
int idx2 = -1;
for(int a = 0; a < r; a++){
for(int b = 0; b < c; b++){
if(a > 0 && Math. abs(grid[a][b]-grid[a-1][b])==1){ g[a][b] = Math. max(g[a][b], g[a-1][b]+1);
}
if(b > 0 && Math. abs(grid[a][b]-grid[a][b-1])==1){ g[a][b] = Math. max(g[a][b], g[a][b-1]+1);
}
if(maxLen {
maxLen = g[a][b];
idx1 = a;
idx2 = b;
}
}
}
display(grid, g, maxLen, idx1, idx2);
}
private static void display(int[][] grid, int[][] g, int maxLen, int idx1, int idx2){
Stack s1 = new Stack<>();
while(maxLen >= 1){
s1.add(grid[idx1][idx2]);
if(idx1>0 && Math. abs(g[idx1-1][idx2]-g[idx1][idx2])= =1){
idx1--;
}
else if(idx2 >0 && Math. abs(g[idx1][idx2-1]-g[idx1][idx2])= =1){
idx2--;
}
maxLen--;
}
Stack s2 = helper(s1);
for(Integer integer : s2){
System. out. print(integer+" ");
}

}
public static Stack helper(Stack input){
Stack tempStack = new Stack();
while(!input. isEmpty()){
int temp = input. pop();
while (!tempStack. isEmpty() && tempStack. peek() > temp){
input push(tempStack. pop());
}
tempStack. push(temp);
}
return tempStack;
}
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:00
Draw the hierarchy chart and design the logic for a program that calculates service charges for hazel's housecleaning service. the program contains housekeeping, detail loop, and end-of-job modules. the main program declares any needed global variables and constants and calls the other modules. the housekeeping module displays a prompt for and accepts a customer's last name. while the user does not enter for the name, the detail loop accepts the number of bathrooms and the number of other rooms to be cleaned. the service charge is computed as $40 plus $15 for each bathroom and $10 for each of the other rooms. the detail loop also displays the service charge and then prompts the user for the next customer's name. the end-of-job module, which executes after the user enters the sentinel value for the name, displays a message that indicates the program is complete.
Answers: 2
question
Computers and Technology, 22.06.2019 16:30
You have inserted new slides based on a word outline. how do you format these new slides to match the powerpoint presentation formatting? a. select all slides in the presentation and click format on the home tab. b. select the new slides and click reset on the home tab. c. select all slides in the presentation and click reset on the home tab. d. select the new slides and click format on the home tab.
Answers: 2
question
Computers and Technology, 23.06.2019 00:00
Which is the correct sequence of steps to set up a document in landscape orientation? a. select page setup from the file menu. then click the margins tab and select landscape. b. select page setup from the edit menu. then click the margins tab and select landscape. c. select page setup from the insert menu. then click the margins tab and select landscape. d. select page setup from the format menu. then click the margins tab and select landscape
Answers: 1
question
Computers and Technology, 23.06.2019 06:20
Which text function capitalizes the first letter in a string of text? question 10 options: upper capital first proper
Answers: 1
You know the right answer?
Written in Java Design a recursive algorithm to find the longest increasing sequence of numbers in...
Questions
question
English, 31.01.2021 23:00
question
Mathematics, 31.01.2021 23:00
question
Mathematics, 31.01.2021 23:00
question
Mathematics, 31.01.2021 23:00
question
Mathematics, 31.01.2021 23:00
question
Biology, 31.01.2021 23:00
Questions on the website: 13722367