Faster Than Light

시간 제한6초메모리 제한1024 MB

요약
길이가 L인 선분의 한 끝을 점수가 있는 칸에 두고, 선분이 스치는 모든 칸의 점수 합이 최대가 되도록 선분을 배치한다. 선분은 격자 밖으로 나가도 되며 좌표는 실수다.
난이도

어려움10점 중 8점

유형
기하, 완전 탐색, 구현, 수학
정답자
아직 제출이 없습니다

문제

In the \textsf{Faster Than Light} video game each spaceship can be represented on a flat grid. All cells of the grid are unit squares. Some cells represent ship sections and they can be fired at. Other sections don't belong to the ship.

There is a beam weapon in the game which shoots in the following way. When fired the weapon draws a line segment of the fixed length LL with the beam over the attacked ship. The position of the segment can be chosen arbitrarily given that one of its ends is positioned inside or on the boundary of one of the sections of the attacked ship. The other end of the segment can be anywhere, including outside the grid. The damage to the ship and its crew depends on the set of sections damaged by the beam. A ship section is considered damaged if the line segment and section cell (including its boundary) have at least one common point.

You are invited to develop a targeting program which should work in the following way. For each spaceship a positive number of points for hitting each of its sections is given. Your program must find the position of the segment which yields the maximum sum of points for all damaged sections.

입력

The first line of the input file contains two integers NN and MM -- the numbers of rows and columns in the grid, respectively (1≤N,M≤301 \le N, M \le 30).

The second line contains the length of the segment --- a real number LL given with two or less digits after decimal point (0.1≤L≤500.1 \le L \le 50).

The next NN lines describe the grid. Each of them contains MM integers. Let the jjth number in the iith of these lines equal a_ija\_{ij} (0≤a_ij≤1070 \le a\_{ij} \le 10^7, i=1…Ni = 1 \ldots N, j=1…Mj = 1 \ldots M). If a_ij=0a\_{ij} = 0, then the corresponding cell is empty. If a_ij>0a\_{ij} > 0, then the cell contains a spaceship section, which yields a_ija\_{ij} points when hit.

It is guaranteed that at least one cell containing a spaceship section is present in the grid. Different spaceship sections may be disconnected from each other.

출력

The output file must contain a single integer -- the maximum possible score for a single shot of the beam.

힌트

The sample test allows to fire the weapon in such a way that it hits two 5-point cells, 1- and 3-point cells, as well as 8- and 1-point cells.

예제1

  1. 예제 1

    입력
    5 4
    2.5
    1 0 5 1
    3 0 3 5
    0 0 0 0
    1 8 1 3
    1 3 1 2
    
    예상 출력
    23