PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000218. Đồng cỏ của cô bò lười (The Lazy Cow (Silver))
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đồng cỏ của cô bò lười (The Lazy Cow (Silver))
The Lazy Cow (Silver)
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
A field is an grid with grass amounts . Bessie chooses a starting cell inside the grid. A step moves to a side-adjacent cell. Find the maximum total grass in cells reachable within steps from the chosen start, counting each cell once, including the start. This is a Manhattan-distance region, not a single walk.
Input
The first line contains . The following lines each contain integers .
Output
Print the maximum total grass.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
5 2
50 5 25 6 17
14 3 2 7 21
99 10 1 2 80
8 7 5 23 11
10 0 78 1 9
Output
342
Explanation
Start at (3,3). The row contributions are 25, 12, 192, 35 and 78.
Example 2
Input
2 0
1 9
4 3
Output
9
Explanation
No movement is allowed; choose cell (1,2).