UV 662 fast food (DP)

Source: Internet
Author: User

From http://blog.csdn.net/shuangde800

Question: Click to open the link

Question

There are n hotels on a straight line road. The coordinates are di.

Select K of the N hotels to build a parking lot. A hotel without a parking lot can only use the nearest parking lot.

Ask about the construction scheme with the least total distance and output it.

Ideas

Perform preprocessing first. sum [I] [J] indicates ~ Create a parking lot between J and I ~ The sum of distance from all hotels in J to the parking lot is the smallest.

In hotel I ~ Between J, building at (I + J)/2 is the solution with the minimum total distance.

F [I] [J] indicates the minimum total distance of Building J parking lots for the first I Hotel
So,
F [I] [J] = min {f [k-1] [J] + sum [k] [I], 1 <= k <= I}

As for the output scheme, the DP output scheme generally stores the "Decision" record and recursively outputs it.

Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.