Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:18:50+00:00 2026-06-17T09:18:50+00:00

I have the next problem I’m having a hard time solving. I have a

  • 0

I have the next problem I’m having a hard time solving.

I have a straight line , and a list of M villages on it. I need to allocate the N railway stations in these villages, so that the average distance of a village from a railway station, will be minimized.
example:

villages: —–1————–2–3———4–5————6———-7—
and we have 3 railway stations.

tried to use dynamic programming, but couldn’t do it. can anyone suggest a way to solv this problem? (except the obvious way of trying all the options)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:18:50+00:00Added an answer on June 17, 2026 at 9:18 am

    I assume that, for each village, you care only about the distance from that village to a particular railway station, not all railway stations. So if you could put a railway station in each village the “average distance from a village to a railway station” would be zero, even if the villages were thousands of miles apart, so that the distance from one village to a different railway station in a different village would be large.

    If you have a group of villages which must all use the same railway station then the best position for that railway station is the median position on the line of the villages (if the number of villages is odd) or anywhere between the middle two villages in the line (if the number of villages is even). This is because if the railway station is anywhere else, moving it towards the median will shorten the distance to the majority of the villages in the group, while increasing the distance only to the minority.

    So an easy approach to this problem is to work out how to divide the M villages into N groups of contiguous villages, each served by a railway station, placed at the median village, or anywhere between the two most central villages in the group.

    This is a dynamic programming problem where you work along the line of villages, computing at village k the best way to divide those k villages up into j groups, and the cost of that best way. You can do this by checking, for each i, of the cost of creating a group from the last i villages and adding on the cost of creating j-1 groups from the first k – i villages.

    If you really mean the average distance between every village and every railway station then note you can just deal with the railway stations one at a time, because the position of one railway station does not affect the cost of positioning another railway station. Then you get N railway stations built on top of each other at the median, or placed along the strip between the two central villages, if there are an even number of villages – which doesn’t really make sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with the next problem... I have a list of values... prices
I have the next problem: I need to process only 1 request at a
I have the next problem. In one of the cells (UITableViewCell) I need to
I have a next problem. I need to represent a pressed keys combination in
I have next problem, when I'm trying to retrieve value from xforms:select elements I
I have next problem: i have a View: <UserControl x:Class=WpfApplication1.UserControl1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008
I have the next problem. I have several PHP systems running in different Windows
I have the next problem: TabControl has three TabPages. Every TabPage has its own
I'm trying to get a regexp to solve the next problem: I have some
Hope find a guru's help to figure out the next problem. I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.