Hi I am trying to solve SUMTRIAN problem it is work good in my computer but when i put the code in the website I have the time limit problem this is my code if any one can help me ,plz? * I am sorry about my English Language
package codechef;
import java.util.Scanner;
class SUMTRIAN {
private static int Trian[][];
//private static int SumTrian[];
private static int rows;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int case1 = input.nextInt();
for (int s = 0;s<case1;s++){
rows= input.nextInt();
Trian = new int[rows*rows][rows*rows];
//SumTrian = new int[rows];
for(int row = 0;row <rows;row++)
for (int col = 0;col<=row;col++)
Trian[row][col]=input.nextInt();
System.out.println(solve(0,0));
}
}
public static int solve(int row,int col){
if(row>rows-1)
return 0;
else{
int t1 = solve(row+1,col);
int t2 = solve(row+1,col+1);
int t = Trian[row][col]+max(t1,t2);
return t;
}
}
public static int max(int t1,int t2){
int max = t1;
if(t2>max)
max = t2;
return max;
}
}