let arr[] stores the value of max amount upto each shop that they can rob.
arr[1]=x[1];
arr[2]=x[2];
for(i=3;i<=n;i++)
{
arr[i]=max{(arr[i-2]+x[i]),arr[i-1]};
}
arr[n] gives the max amount that can be robbed...
correct me if i am wrong.
@prag:has tejas networks visited ur campus?
On Sun, Aug 28, 2011 at 6:34 PM, Prags <[email protected]> wrote:
> Q- There are n consecutive shops. two mafias plan to rob the shops. Each
> shop has cash in their locker. there is one restriction that they cannot rob
> any consecutive shop. write a program that will maximize their profit.
> cash in the shops were given in x[i] i=1...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
Regards,
Kamakshi
[email protected]
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.