×

# what is the problem in my code ?

 2 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;srows-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; } }  asked 27 May '16, 11:58 0★omar61 23●1●3 accept rate: 0%

 2 Your algorithm is doing an exhaustive search and runs in exponential time, that's why it's getting TLE. Try doing a dynamic programming approach :) Good luck! Let me know if you want me to explain how to use DP approach in this problem. answered 27 May '16, 14:43 282●6 accept rate: 11% I found an non-official editorial here: discuss.codechef.com/questions/4557/need-guidance-in-sums-in-triangle-problem#4561 (27 May '16, 14:44) I learned it from tutorial in the code chef by using recursion approach https://www.codechef.com/wiki/recursion-sums-triangle I will try to solve it by DB approach (27 May '16, 17:33) omar610★ Okay brother, good luck :) @omar61 (27 May '16, 17:52)
 0 This might help- https://www.youtube.com/watch?v=ZSNWyyaxFYM answered 21 Nov '16, 17:19 2.6k●6●29 accept rate: 7%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,133
×51
×39

question asked: 27 May '16, 11:58

question was seen: 3,133 times

last updated: 11 Aug '17, 18:23