Solutions to some of NOI 2020 questions

foodie

This data range tells us that this problem requires a fast exponentiation of the matrix.

First consider k = 0 k=0k=0 . Divide each point into five points, then the edge weights are all1 11 , and then a Floyd finds the longest way. Transfer is a generalized matrix multiplication, which satisfies the associative law and can be applied to the matrix fast power.

k ≠ 0 k \ neq 0 k=0 My practice in the examination room is more violent. I directly sort the time of the food festival and ask for violence in sections. The time complexity isO (125 × n 3 × k log ⁡ T) O(125 \times n^3 \times k \log T)O ( 1 2 5×n3×klogT ) , 55 minutes to leave.

Matrix multiplication is an answer matrix multiplied by a transition matrix, because we are from 1 to 11 starts, so the answer matrix only needs the first row. The time complexity isO (25 × n 2 × k log ⁡ T) O(25 \times n^2 \times k \log T)O ( 2 5×n2×klogT)

Making dishes

Did not find n − 2 ≤ mn-2 \leq mn2The nature of m , think about the network flow and burst into zero.

Back to the topic, this property tells us that this question is not a network flow. Then the part is divided into n − 1 ≤ mn-1 \leq mn1m , then considern − 1 = m n-1 = mn1=How m is constructed.

Each time the smallest and largest ddd Take out and make a dish, the smallestddd will be used up, and then the largest remainingddd Throw it back, which is equivalent to reducing the scale of the problem. You can find that this structure is correct. Use a balanced tree or set to maintain it.

For n ≤ mn \leq mnm , you can choose the largestddeach timed to cook, then throw it back untiln − 1 ≤ mn-1 \leq mn1m

For m = n − 2 m = n-2m=n2. Consider changingnnn raw materials are divided into two re-sets, if the sum of the two sets iskkk , then it is equivalent to splitting into twom = n − 1 m=n-1m=n1 situation. This is a typical 01 existence backpack, the complexity isO (n 2 k) O(n^2k)O ( n2 k). Because the state is only 01, it can be optimized with bitset, and the time complexity isO (n 2 k 64) O(\frac{n^2k}{64})O (64n2 K)

Guess you like

Origin blog.csdn.net/qq_39984146/article/details/108144642