编程介的小学生 2017-08-14 07:07 采纳率: 20.5%
浏览 755
已采纳

Banana

Description

Consider a tropical forrest, represented as a matrix. The cell from the right top corner of the matrix has the coordinates (1,1), and the coordinates of the other cells are determinated by the row and the column on which the cell is. In some cells of the matrix are placed banana trees; a cell can contain no more than a banana tree. More banana trees which are neighbours on horizontal or vertical form a region of banana trees. In this kind of region, monkey CEKILI is moving easily, with her well-known agility, from a banana tree to another.
CEKILI is eager and the bananas from a single region are not enough for her. Tarzan wants to help his friend. For that, he may connect exactly k banana tree regions knoting more lianas and so CEKILI could move from a region to another using lianas. Obviously, Tarzan must choose the regions so that the total number of banana trees from those k regions must be maximum.

Detemine maximum number of banana trees which Tarzan can obtain connecting exactly k regions.
Input

The input has the following structure:
Nr K
x(1) y(1)
y(2) y(2)
...
x(Nr) y(Nr)
Nr is the number of banana trees. K is the number of zones which can be connected. x(i) is the row of the i-th banana tree, while y(i) is the column of the i-th banana tree.
There are Constraints:
• 1 <= Nr <= 16000;
• 1 <= x(i), y(i) <= 10000;
• In the tests used for grading k will never be bigger than the number of regions;
• Two positions are horizontally neighbours if they are on the same row and consecutive columns, respectively vertically neighbours if they are on the same column and on consecutive rows.
Output

The output will contain on the first line the maximum number of banana trees that can be obtained by connecting the k regions.
Sample Input

10 3
7 10
1 1
101 1
2 2
102 1
7 11
200 202
2 1
3 2
103 1
Sample Output

9

  • 写回答

1条回答 默认 最新

  • devmiao 2017-08-27 15:49
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog