Re: [algogeeks] Re: TopCoder Bad Neighbour
@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 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 d) { > > int s=d.size(); > > if(s==1){ > return d[0]; > } > > int i,j,k,ans1=0,ans2=0; > int dp1[10],dp2[10]; > dp1[0]=d[0]; > dp1[1]=d[1]; > > // Breaking the circular list into 2 linear lists. > > > // Processing the first list. > for(i=2;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 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 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 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 >> . >> 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 > . > 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.
Re: [algogeeks] Re: TopCoder Bad Neighbour
class BadNeighbors { public: int maxDonations(vector ); }; int dp[51][2][2]; int l; vector v; int solve(int id, int taken, int first) { if(id==l) return 0; int &d = dp[id][taken][first]; if(~d) return d; d = 0; if(id!=l-1) { if(taken==0) { d >?= v[id] + solve(id+1, 1, (id==0) | first); d >?= solve(id+1, 0, first); } else { d >?= solve(id+1, 0, first); } } else { if(first==1) { d >?= solve(id+1, 1, first); } else { if(taken==0) { d >?= v[id] + solve(id+1, 1, first); d >?= solve(id+1, 0, first); } else { d >?= solve(id+1, 0, first); } } } return d; } int BadNeighbors::maxDonations(vector v) { :: v = v; l = v.size(); memset(dp, -1, sizeof dp); return solve(0, 0, 0); } On Wed, Dec 22, 2010 at 9:00 PM, mohit ranjan 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 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 > . > 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.
Re: [algogeeks] Re: TopCoder Bad Neighbour
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 d) { int s=d.size(); if(s==1){ return d[0]; } int i,j,k,ans1=0,ans2=0; int dp1[10],dp2[10]; dp1[0]=d[0]; dp1[1]=d[1]; // Breaking the circular list into 2 linear lists. // Processing the first list. for(i=2;iwrote: > 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 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 > . > 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. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: TopCoder Bad Neighbour
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 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. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.