Luo Gu P4474 Excalibur (Save the Queen title!)

Konjac first made solution to a problem, praise Tell me what the point of a walk QwQ

Topic Link  https://www.luogu.org/problem/P4474

Title Description

https://cdn.luogu.com.cn/upload/pic/17920.png
This is Al-Astoria Pendragon before things become souls, she was going to pull out the sword in the stone to become King Arthur, before that she was going to collect some gems.
Gem n * m are arranged in a grid, each grid has a value of gem v (i, j), and Al · Anatolia Pendragon can choose their starting point.
Start time is 0 seconds. Following operations, performed in sequence per second

  1. When i first started second, Al Anatolia · Pendragon on the grid (x, y), she can take away (x, y) in the gem.
  2. In even second, Anatolia around Al-Pendragon four-frame gems will disappear
  3. If Al Astoria Pande Aragon beginning on the i-th second grid (x, y), i + 1 at the first seconds can be immediately moved to (x + 1, y), (x, y + 1 ), (x-1, y) or (x, y-1), can remain in the (x, y) on.

Al-seeking Anatolia Pendragon up how much the value of gems

Input Format

The first line gives the number N, M represents the number of ranks .N, M is less than or equal to 100, the value does not exceed 10000. The following gem N rows and M columns for describing the digital matrix

Output Format

How much output can get the most value gems

Sample input and output

Input # 1
2 2
1 2
2 1
Output # 1
4

 QwQ, since it is the subject of my king, will certainly be the A

Pre-knowledge of problems: network flow (never learned of children's shoes can go to this Likang Kang https://baijiahao.baidu.com/s?id=1607147031919790970&wfr=spider&for=pc , Los Valley Daily or write very detailed)

Now begin to analyze it (knock on blackboard !!!)

At the beginning of every second Save the Queen can get her gem (only get one) on the station location, in four gems of even second grid will disappear around my king, the title also gives the start time is 0 seconds, At the beginning of my king around four grid will be no stones, then the second, and the first two seconds of the decisions are moving, if two seconds does not move. . . . (Save the Queen slept yet), if you move first, and then stay ,,, that did not get anything, but to make more gems disappear, then move to stay the same is true.

The foregoing analysis (analysis of what in the end), my liege get gems in each even second, and the position of gems adjacent to each other (on their own brain make up about QwQ), we can simplify the title is intended to select the m mutually Pro gems, precious stones makes these m and the maximum value .

Here it is necessary to use knowledge minimum cut (is cut off and the weighted sum of the minimum m edges, so that the source and sink do not communicate) of

The maximum flow equal to the minimum cut

Konjac not want to write a rigorous proof (in fact, will not prove to derive prove what does not exist, this life can not QwQ)

So simple proof is provided below Tell me sir.

。。。。

Minimal cut in the end able Mani

Analysis can know the even slightly gem abscissa and ordinate sum is affirmative adjacent to each other, and also the odd gem.

So we can be horizontal and vertical coordinates of the point source and is connected to an even number of gems, precious stones and is connected to the sink odd, right side for their value (the reverse is also connected to the right side 0 side), adjacent even with each other for the right side of a gem INF side.

Figure built,

 

 

Guess you like

Origin www.cnblogs.com/herolxl/p/11545461.html