Greedy shouldn't work here.
BFS can work, with a special graph, of course - each state should be a triple (x, y, m), where m is a bitmask, representing the subset of collected beepers.
10496 - Collecting Beepers
Moderator: Board moderators
-
- Learning poster
- Posts: 78
- Joined: Sun Nov 30, 2008 5:00 pm
- Location: IUT-OIC, Dhaka, Bangladesh
Re: 10496 - Collecting Beepers
Thank you mf. I will try to sove it using BFS. Thanks for ur help. ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
May be tomorrow is a better day............ ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
-
- Experienced poster
- Posts: 147
- Joined: Mon Jun 07, 2010 11:43 am
- Location: University Of Dhaka,Bangladesh
- Contact:
Re: 10496 - Collecting Beepers
I solved it using recursive backtracking.
UVa stats: http://felix-halim.net/uva/hunting.php?id=63448
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
Re: 10496 - Collecting Beepers
This problem can be solved by recursive backtracking.
The only thing to look at is :http://en.wiktionary.org/wiki/Manhattan_distance
Because this grid has no obstacles in path, so the distance can be directly calculated by Manhattan Distance.
So choose one beeper,backtrack and then choose another
Thanks Brianfry for his concern![:)](./images/smilies/icon_smile.gif)
The only thing to look at is :http://en.wiktionary.org/wiki/Manhattan_distance
Because this grid has no obstacles in path, so the distance can be directly calculated by Manhattan Distance.
So choose one beeper,backtrack and then choose another
![:D](./images/smilies/icon_biggrin.gif)
Thanks Brianfry for his concern
![:)](./images/smilies/icon_smile.gif)
Last edited by dhruba07 on Wed Apr 09, 2014 1:55 pm, edited 1 time in total.
Accept who you are ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10496 - Collecting Beepers
Post your full code.
Check input and AC output for thousands of problems on uDebug!