Give me the source code for this problem

Give me the source code for this problem

Ram likes skiing a lot. That's not very surprising, since skiing is really great. The problem with skiing is one have to slide downwards to gain speed. Also when reached the bottom most point one has to wait for ski-lift to get to higher altitude.

Ram seeks your help to know the longest run possible with the given peaks. That altitude of different peaks is given by a grid of numbers. Look at this example:

7 2 3 4 5 36 37 38 34 6 33 44 46 40 7 24 43 42 41 8 35 32 47 30 9

One can ski down from one peak to a connected peak if and only if the height decreases. One peak is connected to another if it's at left, at right, above or below it. In the sample map, a possible ski path would be 36-33-24(start at 36, end at 24). Of course if one would ski 46-44-43-42-41-30-9....3-2, it would be a much longer run. In fact, it's the longest possible. There could be more than one longest ski path, but all Ram needs from you is to tell maximum number of peaks he could cover for a given map, in this case it is 14.

Input All input comes from input.txt file. The first line contains the number of test cases N. Each test case starts with a line containing the name (it's a single string), the number of rows R and the number of columns C. After that follow R lines with C numbers each, defining the heights. R and C won't be bigger than 100.

Output For each test case, print a line to output.txt containing the name of the area, a colon, a space and the length of the longest run (maximum points covered) one can slide down in that area.

Sample Input 2 Manali 10 5 56 14 51 58 88 26 94 24 39 41 24 16 8 51 51 76 72 77 43 10 38 50 59 84 81 5 23 37 71 77 96 10 93 53 82 94 15 96 69 9 74 0 62 38 96 37 54 55 82 38 Narkanda 5 5
1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

Sample Output Manali: 7 Narkanda: 25

View Answers

January 3, 2013 at 3:06 PM

public class SkiPath { private static Integer[][] peaks = {{7,2,3,4,5}, {36,37,38,34,6}, {33,44,46,40,7}, {24,43,42,41,8}, {35,32,47,30,9}};

private static Integer[][] lRun = {{1,1,1,1,1}, {1,1,1,1,1}, {1,1,1,1,1}, {1,1,1,1,1}, {1,1,1,1,1};

public static int calLongestRun(int i,int j){ int useLeft = -1; int useRight = -1; int useAbove = -1; int useBelow = -1;

if(isAllowed(i,j-1,i,j)) useLeft = 1 + calLongestRun(i,j-1); if(isAllowed(i,j+1,i,j)) useRight = 1 + calLongestRun(i,j+1); if(isAllowed(i-1,j,i,j)) useAbove = 1 + calLongestRun(i-1,j); if(isAllowed(i+1,j,i,j)) useBelow = 1 + calLongestRun(i+1,j); return max(useLeft,useRight,useAbove,useBelow); }

public static int max(int lr,int rr,int ar,int br){ int m=1; if(lr > m) m = lr; if(rr > m) m = rr; if(ar > m) m = ar; if(br > m) m = br; return m; }

public static boolean isAllowed(int x1,int y1,int x,int y){ boolean ret = false; if(x1 >= 0 && y1 >= 0 && x1 < 5 && y1 < 5){ if(peaks[x1][y1] < peaks[x][y]) ret = true; } return ret; }

public static void main(String[] s){ for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ lRun[i][j] = calLongestRun(i,j); } }

int m = 1;

for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(m < lRun[i][j]) m = lRun[i][j]; } }

System.out.println("Longest Run is : "+m); }

}

Output: 14

Ads









Related Tutorials/Questions & Answers:
Give me the source code for this problem
Give me the source code for this problem  Ram likes skiing a lot. That's not very surprising, since skiing is really great. The problem with skiing is one have to slide downwards to gain speed. Also when reached the bottom most
give me source code of webpage creation using html
give me source code of webpage creation using html  how to create a webpage using html
Advertisements
Plz give me code for this question
Plz give me code for this question  Program to find depth of the file in a directory and list all files those are having more number of parent directories
ModuleNotFoundError: No module named 'give_me_code'
ModuleNotFoundError: No module named 'give_me_code'  Hi, My Python... 'give_me_code' How to remove the ModuleNotFoundError: No module named 'give_me_code' error? Thanks   Hi, In your python
verify the code and give me the code with out errors
verify the code and give me the code with out errors   import... clear the errors and give me correct tutorial for my knowledge improving.pls anyone help me. E:\>java add java.lang.NullPointerException at add
Problem with Java Source Code - Java Beginners
Problem with Java Source Code  Dear Sir I have Following Source Code ,But There is Problem with classes, plz Help Me. package mes.gui; import javax.swing.JOptionPane.*; import java.sql.*; import javax.swing.*; import
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
source code
source code  hellow!i am developing a web portal in which i need to set dialy,weekly,monthly reminers so please give me source code in jsp
plz give me answer
plz give me answer  Discuss & Give brief description about string class methods   Java string methods
source code
source code  sir...i need an online shopping web application on struts and jdbc....could u pls send me the source code
source code
source code  sir...i need an online shopping web application on struts and jdbc....could u pls send me the source code
give me a grid example in php
give me a grid example in php  give me easy code example of grid in php like mysql editor
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
source code wanted
data in MS-ACCESS database please explain the problem and to give the source code... data in MS-ACCESS database please explain the problem and to give the source code...-ACCESS database please explain the problem and to give the source code by only
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
Source code
Source code  source code of html to create a user login page
GIVE ME A ANSWER
GIVE ME A ANSWER  Discuss the Number Class in the java.lang package   Number class is an abstract class extended by all classes that represent numeric primitive types such as Byte, Short, Integer, Long, Float
Please give me coding for this..
Please give me coding for this..  Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
reg : the want of source code
) Available Seats and etc. plz Give Me Full Source code with Database...reg : the want of source code  Front End -JAVA Back End - MS Access Hello Sir, I want College Student Admission Project in Java with Source code
give the code for this ques///
give the code for this ques///  write a program in java in which there is a clss readline. the functionality of this class is to read a string from... the following code: import java.util.*; class ReadLine{ public static String
please help me to this problem..
please help me to this problem..  i wrote a program like keyboard... inside the JTextField) but i want to make this program to let me write where i clicked (i.e allows me to write any thing at the field where i clicked
please help me to overcome this problem
please help me to overcome this problem  how to make it easy to write java code. can u please give me suggestions
huffman code give the explanation for this code
huffman code give the explanation for this code  package bitcompress...); } value = 0; bit_count = 0; } } else { int code; bit_array[bit_count++] = bit; if ((code = huffcode_find (bit_array
huffman code give the explanation for this code
huffman code give the explanation for this code  package bitcompress...); } value = 0; bit_count = 0; } } else { int code; bit_array[bit_count++] = bit; if ((code = huffcode_find (bit_array
help me to solve this problem..
help me to solve this problem..  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class Book { String title; //bookâ??s title double price; //bookâ??s price
source code in jsp
source code in jsp  sir...i need the code for inserting images into the product catalog page and code to display it to the customers when they login to site..pls help me
source code for the following question
source code for the following question  source code for the fuzzy c-means
source code in jsp
source code in jsp  i need the source code for online payment in jsp
java/j2ee source code
java/j2ee source code  java/j2ee source code for online food purchasing service with my sql database
java source code
java source code  java source code to create mail server using struts2
please give me an idea to develop a program for this question?
please give me an idea to develop a program for this question?  How to enter a text or number from keyboard without using InputStreamReader method in java
request for java source code
request for java source code  I need source code for graphical password using cued-click points enabled with sound signature in java and oracle 9i as soon as possible... Plz send to my mail
source code security
source code security  how to obfuscate the code? please answer as soon as possible
source code in jsp
source code in jsp  how to insert multiple images in jsp page of product catalog
Help me on the given problem of String
Help me on the given problem of String  class Test { string s1="Hello",s2="lo"; System.out.println((s1=="Hel"+"lo")); System.out.println((s1=="Hel"+lo)); } The above program prints true
Java Source code
Java Source Code for text chat application using jsp and servlets  Code for text chat application using jsp and servlets
Project source code
Project source code  i want source code for contact finder just like facebook provides or linkedin website on der home page just similar to dat...i m working on jsp project ..its a web based project which stores information
hi see and give me reply as soon as possible
hi see and give me reply as soon as possible  Hi Friend, I got path,but it will again ask path error first i was gave index.jsp.It is displayed and it is not going to next level. HTTP Status 404 - /struts/hello type
source code - JSP-Servlet
source code  i want source code for my project online examination it includes two modules user and administrator so if user want to write exam first he register his details and then select the topics on which he want to write
Application context problem code
Application context problem code   now i am posting my code here . i got error of sessionfactory. so tell me where i declare sessionfactory method..."); // code to set test action environment createAction("/create", "Test", "list
attendance management system source code
attendance management system source code  sir i want full ateendance management project please send me source code i am asking so many members... answer so please send code it's very urgent
please give me a java program for the following question
please give me a java program for the following question  Write...; In the previous code, we forget to add an icon to button. So we are sending the updated code. import java.awt.*; import javax.swing.*; import
attendance management project source code
attendance management project source code  sir i want full ateendance management project please send me source code i am asking so many members... answer so please send code it's very urgent
attendance management project source code
attendance management project source code  sir i want full ateendance management project please send me source code i am asking so many members... answer so please send code it's very urgent
combo box code problem
combo box code problem  in this my problem related to : when i select state MP then i wil open the its corresponding city but in database it only stores the option value no like MP at option value 10 then it will stores the 10
Source code of a website in HL and JSP.
Source code of a website in HL and JSP.  I want the source code of a website of 10 pages with database connectivity. Source code should be in HTML and JSP. Thanks
code related problem
code related problem  this code is compiling but not running please help import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Mybutton11 extends JFrame { JTextField text1 = new JTextField(20

Ads