#P1437. [HNOI2004] 敲砖块

    ID: 430 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2004各省省选湖南前缀和

[HNOI2004] 敲砖块

Description

In a trough, there are nn layers of bricks. The top layer has nn bricks, and each lower layer has one fewer brick. Each brick has a score; knocking out a brick yields its score, as shown below:

14 15  4  3  23
 33  33 76  2
   2   13 11
     22 23
       31

If you want to knock out the jj-th brick in the ii-th layer, then if i=1i=1, you can knock it out directly; if i>1i>1, you must first knock out the jj-th and the (j+1)(j+1)-th bricks in layer i1i-1.

You may knock out at most mm bricks. Find the maximum total score you can obtain.

Input Format

The first line contains two positive integers nn and mm; then nn lines follow, describing the scores ai,ja_{i,j} on these nn layers, where 0ai,j1000 \leq a_{i,j} \leq 100.

For 100%100\% of the testdata, it holds that 1n501 \leq n \leq 50, 1mn×(n+1)21 \leq m \leq \frac{n \times (n+1)}{2}.

Output Format

Output a single line containing one positive integer, the maximum total value of the knocked-out bricks.

4 5
2 2 3 4
8 2 7
2 3
49
19

Hint

Translated by ChatGPT 5