Saturday 15 January 2011

Array jump to the end algorithm with weights? -



Array jump to the end algorithm with weights? -

can help me problem?

"a hiker wants go on tour given number of days. route includes several places rest. how hiker has select stops, maximum daily distance low possible?"

example: 59 km within 3 days including 6 possible rests

start --(11 km)--> rest(1) --(16 km)--> rest(2) --(5 km)--> rest(3) --(5 km)--> rest(4) --(12 km)--> rest(5) --(10 km)--> destination(6)

solution: day 1: 11 km day 2: 26 km day 3: 22 km

as @mrcoder pointed out in cooments appears traveling salesman problem.

this problem has it's own wikipedia article here.

the basic thought maintain total distance traveled each stop go point a, point c have go point b, total distance point c point distance b plus b c. point has minumum distance traveled point a, , repeat points reachable point until points in range reached, , minimum distance includes stops , route should taken obtained

now shortest distance between points have been found can find shortest distances between day.

to find if looking n days assume days stop @ first n-1 elements. take total distances on each day , @ lastly day. if lastly days distance greater previous day assume can create distance smaller still, 1 time distance of lastly day has become less number of previous day move on next number. if @ point day has 1 distance stop on set cannot go farther on day.

so lets utilize illustration example distances 11-16-5-5-12-10 looking 3 days split days shown below

11 | 16 | 5-5-12-10 gives total distance traveled each day of 11 | 16 | 32 since 16< 32 11 | 16-5 | 5-12-10 gives 11|21|27 21 < 27 11 | 16-5-5 |12-10 give 11|26|22 ok have found day 3 day 2 11 < 26 adding 11 day 2 set day 1 @ 0 distance cannot move day 1

this hold true if day 2 go 0 elements

example 2

8 - 2 - 16 - 6 - 6 8 | 2 | 16 - 6 - 6 yields 8-2-28 2 < 28 8 | 2 - 16 | 6 - 6 yields 8-18-12 18 > 12 day 3 found 8 - 2 | 16 | 6 - 6 yields 10 - 16 - 12 day 2 has 1 element day 2 found day 1 found

arrays algorithm path

No comments:

Post a Comment