Task description
In this problem, you need to solve a well-known NP problem - the quadratic integer programming problem.
Quadratic integer programming problems have variables: you need to give a length sequence of integers that satisfies all the conditions below.
Quadratic integer programming problems have constraints: the sequence of integers you give needs to satisfy the following two types of constraints:
- Given a positive integer and intervals , where , the sequence you give needs to satisfy for all .
- Given triples , the sequence you give needs to satisfy for all .
The quadratic integer programming problem has an objective function: you are given given weight parameters . Let be the number of elements in the sequence whose value is , and be the number of pairs such that (note that when , and are not the same). The weight of a sequence is:
Your sequence needs to maximize its weight while satisfying the above two constraints.
Quadratic integer programming problems do not necessarily require multiple queries, but we will give queries, each query giving different weight parameters . For each query, you need find a sequence of maximum weight that satisfies the constraints. To reduce the output, you only need to output the weight of this sequence. The data guarantees that at least one sequence that satisfies the above conditions exists.
Input Specification
There are multiple sets of test data for this question. The first line contains a non-negative integer and a positive integer , which represent the test case number and the number of data sets, respectively. indicates that this set of data is a sample.
For each test case:
- The first row contains four integers , describing the sequence range, sequence length, the number of constraints between variables, and the number of queries.
- The next lines each contain two integers , , describing the value range corresponding to each element in the sequence.
- The next lines contain three integers , , each, describing the constraints between a pair of variable.
- Each of the next lines contains non-negative integers describing a set of query weight parameters.
Output Specification
For each set of queries for each set of data, output a row of integers representing the maximum weight of the sequence.
Samples
Sample inputs and outputs can be found here.
Sample 1
See qip/qip1.in and qip/qip1.ans in the player directory. This example satisfies the properties of test point 1 in the data range.
Explanation of Sample 1
In the first test data, the optimal sequences corresponding to the two sets of queries are (1, 2, 2, 1, 3), with c2 = 2, G = 21.
Example 2
See qip/qip2.in and qip/qip2.ans in the player directory.
This example satisfies the properties of test point 3 in the data range.
Explanation of Sample 2
An optimal sequence corresponding to the two sets of queries in the first test data is (4, 4, 3, 3) and (4, 3, 2, 2), respectively.
Sample 3
See qip/qip3.in and qip/qip3.ans in the player directory. This example satisfies the properties of test point 5 in the data range.
Explanation of Sample 3
An optimal sequence corresponding to the three groups of queries in the first test data is (3, 3, 3, 3, 3), (2, 2, 3, 3, 2) and (3, 2, 4, 4, 2).
Sample 4
See qip/qip4.in and qip/qip4.ans in the player directory. This sample satisfies the properties of test point 2 in the data range.
Sample 5
See qip/qip5.in and qip/qip5.ans in the player directory. This sample satisfies the properties of test point 4 in the data range.
Sample 6
See qip/qip6.in and qip/qip6.ans in the player directory. This sample satisfies the properties of test point 8 in the data range.
Sample 7
See qip/qip7.in and qip/qip7.ans in the player directory. This sample satisfies the properties of test point 14 in the data range.
Sample 8
See qip/qip8.in and qip/qip8.ans in the player directory. This sample satisfies the properties of test point 17 in the data range.
Subtasks
Assume \sum q is the sum of q of all test data in a single test point. For all test points,
- ,
- In the i() th test data, ,
- , , ,
- ,
- , ,
- .
Case | Special Property | Points | |||
---|---|---|---|---|---|
1 | 3 | None | 4 | ||
2 | 6 | ||||
3 | 4 | 4 | |||
4 | 6 | ||||
5 | 5 | 5 | |||
6 | 4 | ||||
7 | 4 | ||||
8 | 6 | ||||
9 | 6 | ||||
10 | 5 | ||||
11 | A | 3 | |||
12 | 4 | ||||
13 | 5 | ||||
14 | B | 3 | |||
15 | 4 | ||||
16 | 4 | ||||
17 | C | 4 | |||
18 | 5 | ||||
19 | 5 | ||||
20 | None | 5 | |||
21 | 4 | ||||
22 | 4 |
- Special property A: .
- Special property B: , the sum of m of all test data in a single test point does not exceed .
- Special property C: The data is randomly generated. Specifically, when generating each set of test data in the test point, the parameters k, n, m, q and k non-negative integers p[0], are given to ensure that , then the following rules are used to generate this data:
- For , independent uniform random generation of , then ;
- Keep generating triples as follows until there are m triples:
- Independently and uniformly randomly generate ;
- Randomly generate w with p as weight (for , with probability );
- If there is no sequence after adding to the original triple set, the current triple is discarded, otherwise the current triple is added.
- of each set of queries are independently and uniformly generated randomly within .
Comments