Location>code7788 >text

"Multi-School A-Level Moot 5

Popularity:140 ℃/2024-10-13 10:22:20

A. Good number (number)

Very signed, after typing "Not this question I can do for an hour?"

For each number, sum it with all the previous numbers and store it in a bucket, and then encounter a new number\(a_i\) When enumerating all previous\(a_j,j\in [1,i-1]\)Find out if there is a number in the bucket.\(x\) feasible\(x=a_i-a_j\) Ready to go.

Because there are negative numbers in these numbers, we might think of using themap as a bucket store summation, but this (due to its rather purchase-enabled implementation) is equivalent to hanging an extra\(\log\)The local running time for a large sample is over 3 seconds.

The data range was found to be\(-10^5\le a_i\le 10^5\)Then we add all the numbers\(10^5\)This way there is no negative case, just store it directly in an array. Overall complexity\(O(n^2)\)

B. SOS string (sos)

dp

sign\(f_{i,0/1/2,j}\) Maintaining the answer, the second dimension ranges from 0, 1, and 2 to indicate, respectively, that the first S in SOS is in the i-th bit, that it can be formed into SO with the previous bit, or that it is otherwise.

The third dimension indicates that there are j SOSs now, and if the number is greater than 3, j is also 3.

  • current position\(i\) When the bit is the first S, it can be transferred from the previous bit being S, and the previous bit state being 2:

\[f_{i,0,j}=f_{i-1,0,j}+f_{i-1,2,j} \]

  • When the previous bit can be formed into SO with the previous bit, then the previous bit is S:

\[f_{i,1,j}=f_{i-1,0,j} \]

  • When the current bit is in other state
    • The previous bit can be put S, when the current bit is not O or S, otherwise it belongs to the above two cases;
    • The previous bit can be other, and the current bit is not S at this time;
    • Previous bit is SO, current bit is not S;

\[f_{i,2,j}=f_{i-1,0,j}\times 24+f_{i-1,1,j}\times 25+f_{i-1,2,j}\times 25 \]

  • j > 0, that is, there can be SOS, then the current bit state is 2, can be transferred by SO + S:

\[f_{i,2,j}=f_{i-1,1,j-1} \]

  • The size of j no longer changes when j = 3, written as follows:

\[f_{i,2,j}=f_{i-1,1,j} \]

C. Balloon for the training camps

Unpacking

found that in fact it is 1 to n people choose to choose a blood backpack, either choose or do not choose, because c is small enough, with the total number of programs minus the number of people choose to choose a blood backpack less than the number of programs c can be, so that the number of people choose to choose a blood less than the number of programs c became 01 backpack problem.

Since each modification, one backpack at a time is\(O(nc)\) s, if you do a backpack for each modification, the whole thing is\(O(n^2c)\), so consider returning the backpack.

Each modification is the equivalent of taking the original contribution of the person making the modification out and putting in a new one.

D. Connecting subtrees to the center of gravity of the tree (tree)

Qyun's delicious blog