Programming beauty Reading Notes 15: 4.5 tape file storage Optimization

Source: Internet
Author: User

Programming beauty Reading Notes 15: 4.5 tape file storage Optimization

 

For an arrangement that is already the optimal solution, remember that the length of the I-th file is Bi, and the probability of being accessed is Ai. If you swap the I and I + 1 files, the average length will not decrease. After the swap, When you access the original I files, to access an I + 1 file, the length of the file is increased by AI * Bi + 1, the length of the first and second files is reduced by AI + 1 * bi. The length of the files before and after the two files is not changed, so there are:

AI * Bi + 1-ai + 1 * bi> = 0That isAI/Bi> = ai + 1/Bi + 1,

Because I can be arbitraryA0/B0> = A1/B1> = a2/B2> =... > = An-1/Bn-1. That is to say, the optimal solution must meetP [I]/L [I]Sort in descending order, in descending order, values of P [I]/L [I] can only be uniquely ordered (only the values of P [I]/L [I] are considered, if the P [I]/L [I] values of the two files are the same, their locations can be swapped without affecting), this arrangement must be the optimal solution. Therefore, the original problem is equivalent to"Sort P [I]/L [I] in descending order".

 

 

Similar questions:

"Concatenates a given natural number array to obtain a number and calculates the maximum or minimum value of the number ".

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.