87 analog solution to a problem

A. maze

Done similar problems, to maintain the shortest $ k $ of a convex hull, and the answer is the convex hull $ y = s $ abscissa intersection of the straight line, this is also hard to fight.

However, the answer is clearly monotone, so the direct half the answer would be finished.

Indeed, the answer to this binary operation is equivalent to the selected line $ x = mid $,

Obtaining $ x = MID $ intersection of the ordinate with the convex hull, and compared to determine the final answer by $ MID $ i.e. the ordinate and $ s $.

 

 

 

B. bird

The move transformed human bird movement, the problem is adjacent to $ k $ positions up to play a shot.

Set $ ​​dp_i $ represents the last shot to play in the $ i $ at the optimal answer.

There then transferred $ dp_i = dp_j + cnt_ {j, i} $, $ cnt_ {j, i} $ $ J $ denotes the number of hit but not at $ I $ can hit the bird.

This thing is not difficult to maintain,

For each bird, as long as we

To $ dp_0 $ ~ $ dp_ L_i $ $ in the {l-1} $ plus 1,

In the $ r_ {i + 1} $ at a $ dp_0 $ ~ $ dp_ {l-1} $ subtracting 1,

Addition and subtraction operations with a tree line, maintaining the most value would be finished.

 

 

 

C. stone

Set $ ​​f (i, j) $ represents the point of $ (i, j) $ is legitimate only $ 0 / $ 1 has two values.

There Transfer

$a[i]=b[j]$  $f[i+1][j+1]=f[i][j]$

$a[i]!=b[j]$  $f[i+1][j]=f[i][j],f[i][j+1]=f[i][j]$

Obviously for the same $ i $, $ f (i, j) $ 1 $ value of approximately $ interval is continuous, the left and right end points are provided $ l_i $, $ r_i $.

$ L $, R & lt Seeking $ $ array is simple.

However $ l_i, not all within the scope of r_i $ 1 to $ $, which is peppered with $ 0 $.

Total answers is $ l_i $, $ r_i $ range minus the number of which $ 0 $.

May wish to play table, in fact, play table tells us, the conclusion is: The answer is to subtract $ b $ string $ l_i $, in the $ r_i $ range,

String $ s = a [i-1], a [i] is the number of substrings $ reverse order, i.e. $ l_i <= j <= r_i $ $ a [i] == b [j-1], a [i-1] == b [j], a [i]! = a [i + 1] $ number.

In short, the answer is: $ ans = \ sum \ limits_ {i = 1} ^ {n} r_i-l_i + 1- \ sum \ limits_ {j = l_i} ^ {r_i} [a [i] == b [ j-1], a [i-1] == b [j], a [i]! = a [i + 1]] $

Because $ l $, $ r $ array not fall monotonically, with only the character set $ A, B, C $.

It can be obtained directly after a monotone pointer summation, and of course also possible prefixes.

 

$ 0 $ considering what it means to the table.

Because $ a [i-1]! = B [j-1] $ $ a [i-1] == b [j] $ $ a [i] == b [j-1] $ $ a is equivalent to $, $ b $ string formed in reverse order.

We determined from the number of reverse sequence value is equal to $ f $ $ $ 0 to the number of points, so to prove that :( note below $ f [i] [j] $ $ J guaranteed at $ $ l_i, r_i within the $ range)

$ F [i] Sufficient Conditions [j] = 0 $ is

1.$a[i-1]!=b[j-1]$

2.$a[i-1]==b[j]$

3.$a[i]==b[j-1]$

 

Because $ f [i] [j] $ not $ f [i-1] [j-1] $ transfer, then $ f [i-1] [j-1] == 0 $ or $ a [i- 1]! = b [j-1] $.

Because $ f [i] [j] $ not $ f [i-1] [j] $ transfer, then $ f [i-1] [j] == 0 $ or $ a [i-1] == b [j] $

Because $ f [i] [j] $ not $ f [i] [j-1] $ transfer, then $ f [i] [j-1] == 0 $ or $ a [i] == b [ j-1] $

Because there are three or its sufficiency is obvious.

 

The following evidence $ f [i-1] [j] = 1 $ and $ f [i] [j-1] = 1 $, i.e., the conditions 23 are necessary:

1. Assuming $ f [i-1] [j-1] = 1 $, then the $ f [i] [j] = 0 $,

$ F [i-1] [j-1] $ must be transferred to the $ f [i-1] [j] $ and $ f [i] [j-1] $, so $ f [i-1] [ j] = f [i] [j-1] = 1 $.

2. Assuming $ f [i-1] [j-1] = 0 $, the above evidence, we can summarize that $ f [i-1] [j-2] = 1 $,

由于$f[i-1][j-1]=0$,那么$f[i-1][j-2]$必定要转移到$f[i][j-1]$,所以$f[i][j-1]=1$,同理可得$f[i-1][j]=1$。

证毕。

 

下面证条件1是必要的:

1.假设$f[i-1][j-1]=1$,那么显然是必要的。

2.假设$f[i-1][j-1]=0$,那么在$(i-1,j-1)$,字符串$a$,$b$已经形成了逆序串,那么显然$a[i-1]!=b[j-1]$。

 

所以上述三个条件是充要的,$(i,j)$存在逆序串等价于$f[i][j]=0$,所以我们的计算是合理的。

Guess you like

Origin www.cnblogs.com/skyh/p/11740763.html