×

# 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.5k●3●19 accept rate: 8%
 0 Also, besides DP, you should take care to never name any package while submitting it on any online judge. answered 02 Mar, 17:21 360●9 accept rate: 0%
 0 Economics Assignment Help discusses the subject in much detail facilitation on many topics relating to economics, for instance invisible hand; Malthus thoughts about population growth; scarcity, choice, and self-interest within economics and other topics like demand side economics, socio-economics, macroeconomics, microeconomics, aggregate supply, aggregate demand and much more. answered 14 Apr, 17:44 0★cubi -5 accept rate: 0%
 0 answered 29 Jun, 15:32 -3 accept rate: 0%

# include<iostream>

using namespace std; long a[100][100]; long sum[100]; int temp,temp1,k; int main() { int m,i,j,n,N; temp=0; temp1=1; k=0; cin>>n; while(n>0) {
cin>>N; for(i=0;i<n;i++) for(j="0;j&lt;=i;j++)" {="" cin="">>a[i][j]; } for(i=1;i<=N;i++) { j=0; temp=a[i][j]; for(j=0;j<=i;j++) { if(temp<=a[i][j]) { temp=a[i][j]; } } temp1=temp1+temp; if(i==(N)) { sum[k]=temp1; if(k==0) { --sum[k]; } k++; temp1=0; } } n--; } for(i=0;i<k;i++) { cout<<sum[i]<<"\n"; } return 0; } What's Wrong with my code?

1
accept rate: 0%

 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,051
×47
×37

question asked: 27 May '16, 11:58

question was seen: 2,968 times

last updated: 11 Aug, 18:23