#P1398. [NOI2013] 书法家

    ID: 392 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2013NOI 系列枚举,暴力

[NOI2013] 书法家

Description

Student Xiao E loves calligraphy. He heard that NOI2013 has started, and he wants to write the word "NOI" to give to everyone.

Xiao E has a magical sheet of paper, which can be represented as a 2D grid of nn rows and mm columns. For convenience, we define the lower-left cell of the grid to have coordinates (1,1)(1, 1), and the upper-right cell to have coordinates (m,n)(m, n).

Each cell in the grid has an integer luck value. Writing on the cells increases everyone’s luck. The total luck equals the sum of the luck values of all the cells touched by the brush. Now you need to write the three letters N, O, and I on the paper.

Definitions of the three calligraphic letters:

  • N consists of several (at least 33) rectangles whose edges are parallel to the coordinate axes. Suppose it consists of KK rectangles (indexed 1K1 \ldots K). Let the lower-left cell of the ii-th rectangle be (Li,Bi)(L_i, B_i) and the upper-right cell be (Ri,Ti)(R_i, T_i). They must satisfy:
    1. LiRi,BiTiL_i \le R_i, B_i \le T_i.
    2. For any 1<iK1 < i \le K, Li=Ri1+1L_i = R_{i-1} + 1.
    3. For any 3i<K3 \le i < K, Bi11TiTi1B_{i-1} - 1 \le T_i \le T_{i-1}, BiBi1B_i \le B_{i-1}.
    4. B2>B1B_2 > B_1, T2=T1T_2 = T_1, BK1=BKB_{K-1} = B_K, TK1<TKT_{K-1} < T_K.
  • O is formed by taking a large rectangle AA and removing a smaller rectangle BB from its interior. Both rectangles are axis-aligned. Let the lower-left cell of the large rectangle AA be (u,v)(u, v), with width WW and height HH. Then the small rectangle BB has lower-left cell (u+1,v+1)(u + 1, v + 1), width W2W - 2, and height H2H - 2. They must satisfy:
    1. W3W \ge 3, H3H \ge 3.
    2. u>RK+1u > R_K + 1.
  • I consists of 33 solid rectangles whose edges are parallel to the coordinate axes and are stacked from bottom to top, indexed 1,2,31, 2, 3 from bottom to top. Let the lower-left cell of the ii-th rectangle be (Pi,Qi)(P_i, Q_i) and the upper-right cell be (Gi,Hi)(G_i, H_i). They must satisfy:
    1. PiGi,QiHiP_i \le G_i, Q_i \le H_i.
    2. P1=P3>u+WP_1 = P_3 > u + W, G1=G3G_1 = G_3.
    3. Q1=H1=Q21Q_1 = H_1 = Q_2 - 1, H2+1=Q3=H3H_2 + 1 = Q_3 = H_3.
    4. P1<P2G2<G1P_1 < P_2 \le G_2 < G_1.

An example of N, O, and I is shown below:

In addition, all drawn shapes are not allowed to go beyond the boundaries of the paper. Now Xiao E wants to know the maximum total luck he can achieve.

Input Format

The first line contains two positive integers nn and mm, representing the number of rows and columns of the matrix, respectively.

Then nn lines follow, each containing mm integers. In the (i+1)(i + 1)-th line, the jj-th number is the luck value of cell (j,ni+1)(j, n - i + 1).

Output Format

Output an integer TT, which is the maximum total luck that Xiao E can obtain.

3 13 
1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 
1 -1 1 -1 1 -1 1 -1 1 -1 -1 1 -1 
1 -1 -1 1 1 -1 1 1 1 -1 1 1 1 

24
3 13
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1


-20

Hint

Sample Explanation 1

Sample Explanation 2

Constraints

Test point ID nn mm Luck value range
1 =3=3 =12=12 [50,50][-50,50]
2 ^ ^
3
4
5 10\le10 20\le20
6 ^
7
8
9 150\le150 500\le500 =1=1
10 ^
11 80\le80 [200,200][-200,200]
12 ^ ^
13
14
15 150\le150 500\le500
16 ^
17
18
19
20

For all testdata, it is guaranteed that n3,m12n \ge 3, m \ge 12.

Translated by ChatGPT 5