1109: [poi2007] stacked wood klotime limit: 10 sec memory limit: 162 MB
Submit: 530 solved: 172
[Submit] [Status] Description
Mary has some building blocks in her birthday present. The blocks are cubes of the same size. Each building block has a number on it. Mary built a tower with all his blocks. Mom told Mary that the game aims to build a tower so that the most blocks are in the correct position. The correct position of a building block with several I numbers is the position where the tower is counted from bottom to top. Mary decided to move some from the existing tower so that the most blocks were in the correct position. Please tell Mary which blocks should she remove.
Input
The first act of the input file is N, indicating the initial height of the tower. The second row contains N numbers A1, A2,..., An, indicating the number of blocks from bottom to top. (1 <= n <= 100000,1 <= AI <= 1000000 ).
Output
Note: The maximum number of output points can be in the correct position.
Sample input5
1 1 2 5 4 sample output3hint
Source
Question:
This question has been put on hold for several weeks...
At first, I thought of direct Lis, and thought it was a positive solution. Then I went crazy about Wa. After reading the question solution of seter, I realized that I had underestimated POI's question 233333.
Seter question:
Bytes -------------------------------------------------------------------------------------------------
First, list the DP equation. F [I] is the maximum number of places in the first I block when the I block is located on its own.
F [I] = max {f [J] | I> J, a [I]> A [J], A [I]-A [J] <= I-j} + 1
A [I]> A [J] ensures that J is in its own position, A [I]-A [J] <= I-j is used to ensure that there are enough blocks in the middle so that I can be in the position of a [I.
To make each limit only related to the location, A [I]-A [J] <= I-j can be deformed into a [I]-I <= A [J]-J.
It seems like a lis! // I think of it here, thanks ....
The question is, there are two variables in this thing. Do you want to mess up like lis2?
Let's add up the following two formulas,
1: A [I]-I <= A [J]-j =>-A [I] + I> =-A [J] + J
2: A [I]> A [J]
I> j ...... If a [I]> A [J] And a [I]-I <= A [J]-J, I> J is required!
Then you only need to sort by a [I]-I (you want to sort by a [I], so that the two numbers are equal when the lis is obtained ), find Lis.
When a [I]-I is equal, the ascending order of a [I] can maximize the answer, so the second keyword in the sorting should be a [I].
Bytes -------------------------------------------------------------------------------------------------
The final conversion of God, I will wait for zookeeper to only support orzzzzzzz
Code:
Bzoj1109: [poi2007] stacked wood klo