"Network flow 24 questions----02" Space flight plan

Source: Internet
Author: User

Problem Description:

Professor W is planning a series of space flights for the National Space Center. Every space flight can make a series of commercial experiments to gain profits. A selection of experimental set E={e1,e2,...,em} has been identified, and the set of all instruments required for these experiments to be used I={i1,i2, ... in}. The experiment EJ needs to use the instrument is a subset of I RJ belongs to I. The cost of configuring the instrument IK is ck USD. The sponsors of the experiment EJ have agreed to pay PJ dollars for the results of the experiment. Prof W's task is to find an effective algorithm to determine which experiments are to be carried out in a space flight and which instruments will be used to make space flight the largest net yield. The net income here is the difference between the full amount of revenue obtained from the experiment and the total cost of the equipment being configured.

Programming tasks:
For a given experiment and instrument configuration, the program is programmed to find the maximum net yield.
Data input:
The input data is provided by the file Input.txt. The 1th line of the file has 2 positive integers m and N. M is the number of experiments, and N is the number of instruments. The next M-line, each row is an experimental data. The first number of sponsors agree to pay the fee for the experiment
The number of instruments to be used in the experiment. The number of n in the last line is the cost of configuring each instrument.
result output:
At the end of the program, the best protocols are output to the file output.txt. Line 1th is the experiment number; line 2nd is the instrument number; the last line is net income.
Input File Example
2 3
10 1 2
25 2 3

5 6 7

Output File Example

1 2
1 2 3
17

The most powerful closed graph problem can be transformed into a minimum cut problem, and then solved with maximum flow.

Build diagram:
(1): from S to each XI connect a capacity for that point of revenue of the forward edge. W: (+)
(2): From Yi to t connect a capacity for the point of expenditure of the forward side. W:-(-)
(3): If an experiment I need device J, connect a line from XI to YJ capacity for infinity of the forward side. W:inf

Code Simple yo

"Network flow 24 questions----02" Space flight plan

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.