#P8501. [NOI2022] 二次整数规划问题
[NOI2022] 二次整数规划问题
Problem Description
In this problem, you need to solve a famous NP problem—the quadratic integer programming problem.
The quadratic integer programming problem has variables: you need to give an integer sequence of length that satisfies all conditions below.
The quadratic integer programming problem has constraints: the integer sequence you give must satisfy the following two types of constraints:
- The first type constrains the value of each single variable: given a positive integer () and intervals (), where , your sequence must satisfy , .
- The second type constrains the values between variables: given triples , your sequence must satisfy , .
The quadratic integer programming problem has an objective function: given objective parameters (note that the index range is from to ), for an integer sequence with value range , let be the number of elements in the sequence whose value equals , and let be the number of integer ordered pairs satisfying and . Note that when , and are different ordered pairs. Define the weight of this sequence as
$$W(p_1, p_2, \ldots, p_n) = 10^6 G+\sum_{i=2}^{k-1} c_i v_i \text{。}$$Your sequence needs to maximize its weight while satisfying the two types of constraints above. It is guaranteed that, under the given constraints, there exists a sequence that satisfies them.
The quadratic integer programming problem does not have to include multiple queries, but we will give queries. Each query provides different weight parameters . For each query, you need to find a sequence that satisfies the constraints and maximizes the weight. To reduce the output size, you only need to output the weight of this sequence.
Input Format
This problem contains multiple test cases. The first line contains a non-negative integer and a positive integer , representing the test point ID and the number of testdata. indicates that this set of data is a sample.
For each testdata, the first line contains four integers , describing the sequence value range, the sequence length, the number of constraints between variables, and the number of queries.
The next lines each contain two integers , describing the allowed value interval for each element in the sequence.
The next lines each contain three integers , describing one constraint between variables.
The next lines each contain non-negative integers , describing the weight parameters of one query.
Output Format
For each query of each testdata, output one line containing one integer, representing the maximum possible weight of the sequence.
Hint
[Sample #1]
See qip/qip1.in and qip/qip1.ans in the attachment.
This sample satisfies the property of test point in the Constraints.
[Sample Explanation #1]
In the first testdata, the optimal sequence for both queries is , where .
[Sample #2]
See qip/qip2.in and qip/qip2.ans in the attachment.
This sample satisfies the property of test point in the Constraints.
[Sample Explanation #2]
In the first testdata, the optimal sequences for the two queries are and .
[Sample #3]
See qip/qip3.in and qip/qip3.ans in the attachment.
This sample satisfies the property of test point in the Constraints.
[Sample Explanation #3]
In the first testdata, one optimal sequence for the three queries is , , and .
[Sample #4]
See qip/qip4.in and qip/qip4.ans in the attachment.
This sample satisfies the property of test point in the Constraints.
[Sample #5]
See qip/qip5.in and qip/qip5.ans in the attachment.
This sample satisfies the property of test point in the Constraints.
[Sample #6]
See qip/qip6.in and qip/qip6.ans in the attachment.
This sample satisfies the property of test point in the Constraints.
[Sample #7]
See qip/qip7.in and qip/qip7.ans in the attachment.
This sample satisfies the property of test point in the Constraints.
[Sample #8]
See qip/qip8.in and qip/qip8.ans in the attachment.
This sample satisfies the property of test point in the Constraints.
[Constraints]
Let be the sum of over all testdata in a single test point. For all test points,
- .
- In the -th () testdata, .
- , , .
- .
- , .
- .
| Test Point ID | Special Property | Score | |||
|---|---|---|---|---|---|
| None | |||||
| A | |||||
| B | |||||
| C | |||||
| None | |||||
Special Property A: .
Special Property B: , and the sum of over all testdata in a single test point does not exceed .
Special Property C: The data is generated randomly. Specifically, when generating each testdata in the test point, parameters and non-negative constants are given, and it is guaranteed that . Then the data is generated by the following rules:
- For , independently generate uniformly at random, then .
- Repeatedly generate triples as follows until there are triples:
- Independently generate uniformly at random.
- Randomly generate with weights (for , the probability that is ).
- If after adding to the existing set of triples, there is no sequence satisfying all constraints, then discard this triple; otherwise, keep it.
- For each query, are independently generated uniformly at random in .
Translated by ChatGPT 5