@Amit, please refer http://www.topcoder.com/tc?module=Static&d1=match_editorials&d2=tccc04_online_rd_4
the recurrence relations is f(x) = max(f(x-2)+element[x], f(x-3)+element[x-1]) you are missing the 2nd part here Mohit On Wed, Dec 22, 2010 at 9:55 PM, Amit Jaspal <amitjaspal...@gmail.com>wrote: > Hi all, > > I was trying this question and I got the jist of it I guess but still its > not getting accepted > > Can anybody tell me what am I doing wrong?? > > > ******************************************************************************** > int BadNeighbors::maxDonations(vector <int> d) { > > int s=d.size(); > > if(s==1){ > return d[0]; > } > > int i,j,k,ans1=0,ans2=0; > int dp1[100000],dp2[100000]; > dp1[0]=d[0]; > dp1[1]=d[1]; > > // Breaking the circular list into 2 linear lists. > > > // Processing the first list. > for(i=2;i<s-1;i++){ > dp1[i]=max(dp1[i-1],(dp1[i-2]+d[i])); > } > ans1=dp1[s-2]; > > > // Processing the second list. > dp2[1]=d[1]; > dp2[2]=d[2]; > for(i=3;i<s;i++){ > dp2[i]=max(dp2[i-1],(dp2[i-2]+d[i])); > } > ans2=dp2[s-1]; > > return max(ans1,ans2); > > } > > > ************************************************************************************************* > > > On Wed, Dec 22, 2010 at 9:00 PM, mohit ranjan <shoonya.mo...@gmail.com>wrote: > >> Ok, I got the recurrence relation at >> >> http://www.topcoder.com/tc?module=Static&d1=match_editorials&d2=tccc04_online_rd_4 >> >> >> Mohit >> >> >> >> On Wed, Dec 22, 2010 at 8:33 PM, mohit ranjan <shoonya.mo...@gmail.com>wrote: >> >>> Hi All, >>> >>> Can anybody help me with some hint for >>> http://www.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009 >>> >>> >>> Mohit >>> >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Amit Jaspal > Btech IT IIIT- Allahabad > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.