Re: [algogeeks] SPOJ DP : SUMITR

2011-03-08 Thread Wladimir Tavares
This my code: #include stdio.h #define R(i,b) for(i=0;ib;i++) #define D(i,a) for(i=a;i=0;i--) #define I(d) scanf(%d,d); main(){int t,n,i,j,m[100][100];I(t) while(t--){I(n)R(i,n)R(j,i+1)I(m[i][j]) D(i,n-2)R(j,i+1)m[i][j] += m[i+1][j] m[i+1][j+1]?m[i+1][j]:m[i+1][j+1];printf(%d\n,m[0][0]);}} 297

Re: [algogeeks] SPOJ DP : SUMITR

2011-03-08 Thread Wladimir Tavares
I create some macros like this: #define R(i,a,b) for(i=a;ib;i++) #define D(i,a,b) for(i=a;i=b;i--) #define I(d) scanf(%d,d); But i don't get the accepted in this problem! On Sun, Mar 6, 2011 at 1:55 PM, Logic King crazy.logic.k...@gmail.comwrote: i solved the problem on spoj based on DP

Re: [algogeeks] SPOJ DP : SUMITR

2011-03-08 Thread Logic King
Well tried, i have got the correct answer after working on it for almost 2 hours here is my code #includeiostream using namespace std;int a[100][100];main(){int

Re: [algogeeks] SPOJ DP : SUMITR

2011-03-08 Thread abhijith reddy
algorithm isn't required for C++ 4.0.*. The same code will give Compile Error in C++ 4.3 and above On Tue, Mar 8, 2011 at 10:42 PM, Logic King crazy.logic.k...@gmail.comwrote: Well tried, i have got the correct answer after working on it for almost 2 hours here is my code

Re: [algogeeks] SPOJ DP : SUMITR

2011-03-08 Thread Logic King
I submitted it in g++4.3.2 it was AC...but acc. to you it should have been error...i think you are wrong somewhere !! On Tue, Mar 8, 2011 at 10:46 PM, abhijith reddy abhijith200...@gmail.comwrote: algorithm isn't required for C++ 4.0.*. The same code will give Compile Error in C++

Re: [algogeeks] SPOJ DP : SUMITR

2011-03-08 Thread Saikat Debnath
My accepted solution. I am using DP to precompute, each interval. ar[i][j] gives the answer for interval i to j; for(i=0;in;i++) ar[i][i] = v[i]*n; for(i=n-2;i=0;i--) for(j=i+1;jn;j++) ar[i][j] = max(ar[i+1][j]+v[i]*(n-(j-i)),ar[i][j-1]+v[j]*(n-(j-i))); output