#P3888. [GDOI2014] 拯救莫莉斯

    ID: 2825 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2014各省省选广东枚举,暴力状态压缩,状压进制

[GDOI2014] 拯救莫莉斯

Description

Morris Qiao is a formidable figure in the Sanctuary. With his outstanding economic acumen, he firmly controls the oil market there.

The map of the Sanctuary can be seen as an n×mn \times m grid. Each integer coordinate (x,y)(x, y) represents a city (1xn,1ym1 \le x \le n, 1 \le y \le m). The definition of adjacency between two cities is: for cities (Ax,Ay)(A_x, A_y) and (Bx,By)(B_x, B_y), they are adjacent if (AxBx)2+(AyBy)2=1(A_x - B_x)^2 + (A_y - B_y)^2 = 1.

Because the total volume of oil trade in the Sanctuary is large, Morris realizes that he cannot dispatch every oil order from the same depot. To improve efficiency, Morris Qiao decides to build depots in some cities, so that every city XX satisfies one of the following:

  1. City XX has a depot itself.
  2. There exists a city YY with a depot, and city XX is adjacent to city YY.

As on Earth, land prices may differ between cities in the Sanctuary, so Morris wants to minimize the total cost of achieving the goal. If multiple plans have the same minimum total cost, to facilitate management, Morris will choose the one with fewer depots.

Input Format

The first line contains two positive integers n,mn, m (with n×m50n \times m \le 50 and mnm \le n), representing the size of the grid.

Then follows an nn-by-mm matrix FF, where Fi,jF_{i, j} denotes the cost to build a depot in city (i,j)(i, j).

Output Format

Output two numbers: the number of depots and the minimum total cost.

3 3
6 5 4
1 2 3
7 8 9
3 6

Hint

For 30%30\% of the testdata, n×m25n \times m \le 25.
For 100%100\% of the testdata, n×m50n \times m \le 50, 0Fi,j1050 \le F_{i, j} \le 10^5.

Translated by ChatGPT 5