ABC248 Note

· · 算法·理论

Too easy to be necessary to say.

Knapsack and suffix sum.

Preprocess the occurrences of every number and use binary search for queries.

If K=1, obviously the answer is \texttt{Infinity}.

Otherwise, enumrate two points. Ensure these points are the first two points on the line. If there are at least K points, add one to the answer.

Use integer to avoid precision error.

Let dp_{i,j,0/1}= the number of ways to fill the first i columns and throw away j edges and the two points in the last column are connected/unconnected.

Time complexity: O(N^2).