POJ 1018 Communication System [enumeration]

Source: Internet
Author: User

General question:
A company wants to establish a communication system, which requires n kinds of equipment, and each equipment can have m1, m2, m3,..., mn manufacturers respectively
Production is provided, and the same equipment produced by each manufacturer has two differences: bandwidth widths and Price prices.
One device is required for each device. Considering the cost-effectiveness, n devices must be selected to maximize B/P.
B is the minimum bandwidth of the n devices, and P is the total bandwidth of the n devices.

 


Solution:


First, we need to make it clear that to maximize B/P, we need to make B as big as possible, and P as small as possible.

Since B and P are two mutually restrictive variables, and they have to get the extreme values as much as possible at the same time, then one of the shader values can be "temporarily fixed.

The number of input lines is the number of device types, that is, the I-th line describes the I-th devices and provides the product information of the manufacturers of I-th devices.

 

Use enumeration + pruning:

First, the value of B must be a certain bandwidth value of all devices produced by the manufacturer. Therefore, we can enumerate all the bandwidths. Each time we enumerate the value of B, the value of B is "temporarily fixed.

Second, record that the selected B belongs to the k-type device. Then, select n-1 devices from the remaining devices, the bandwidth of the selected device must be greater than or equal to B (this is determined by the question), and the price is the minimum value to meet the bandwidth requirements.

After n devices are selected, calculate B/P and then enumerate the next B. Repeat the preceding operation. Compare the B/P values of different B values. The biggest one is the answer.

 

Pruning method:

Preparations:

1. Recording before input: For each device, the maximum bandwidth provided by the manufacturer MaxB []

2. Sort all devices (regardless of whether they are of the same type) in ascending order. The bandwidth is the first keyword, the price is the second keyword, and the device category number (1 ~ N) is the third keyword. Stored in the one-dimensional array dev [] After sorting

Pruning:

1. from small to large, the bandwidth of each device in dev [] is used as the B value. If the total number of devices is m, the bandwidth is from 1 to m-(n-1 ). This is because at least n types of devices need to be selected from the enumeration position, and m-(n-1) is the upper limit, that is, the last n devices are n types respectively.

2. When B is enumerated, if B is found to be larger than the maximum bandwidth of a device, you do not need to continue enumeration and output the previous B/P value. This is because B is the minimum bandwidth of all devices. If the maximum bandwidth of a device is smaller than B, B's selection is illegal, dev [] has been sorted in ascending order of B. The value of B is larger and cannot be true. Therefore, you do not need to continue enumeration.

3. During the B value enumeration process, for each B value, when selecting another device, you must record the number of devices of different types, count. Finally, when count is less than n, it means that there are no n-1 devices in the remaining devices after the value of B. You can directly jump out of the enumeration.

----------------------------- // The above analysis

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.