/// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100010 int m, dp[MX], row[MX], arr[MX]; int func(int pos) { if(pos>=m) return 0; int &ret = dp[pos]; if(ret!=-1) return ret; ret = max(func(pos+1), func(pos+2)+arr[pos]); return ret; } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int tc, kk=1, n; string s; char ch; while(cin>>n>>m && n) { for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cin>>arr[j], dp[j]=-1; //SET(dp); row[i]=func(0); } //SET(dp); for(int i=0;i<n;i++) arr[i]=row[i], dp[i]=-1; m=n; cout<< func(0) <<"\n"; } return 0; }
Sunday, 20 September 2015
UVA - 12146 Candy ( UVALive - 4212, SPOJ - SAMER08C, Regionals 2008 >> Latin America - South America)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment