HBC224036子序列,贪心,动态规划Problem G : Garden题解

痛心疾首 算法基础篇 73 0
题库丰富多样,涵盖各个领域,全网最全C++题库,让您在练习中不断成长!
There is a rectangle garden in front of Gina’s house. The garden can be seen as an n-by-m rectangular grid. All grid cells are identical squares, and two grid cells are considered adjacent if they share an common edge. Gina loves cacti and wants to plant as many cacti as possible in the garden. However, there are some constraints on planting cacti. The soil can be too wet in some of the cells and therefore is not suitable for cacti. Gina cannot plant cacti in those cells. Since the soil in each cell is not fertile enough to grow two or more cacti, Gina may plant at most one cactus in a cell. At most one cactus can be planted in any pair of adjacent cells. Otherwise, the cacti in those cells may be harmed by their neighbor’s thorns. Please write a program to help Gina calculate the maximum possible number of cacti can be planted, and also a way of plantings that meet the listed constraints.

There is a rectangle garden in front of Gina’s house. The garden can be seen as an n-by-m rectangular grid. All grid cells are identical squares, and two grid cells are considered adjacent if they share an common edge. Gina loves cacti and wants to plant as many cacti as possible in the garden. However, there are some constraints on planting cacti.     • The soil can be too wet in some of the cells and therefore is not suitable for cacti. Gina cannot plant cacti in those cells.     • Since the soil in each cell is not fertile enough to grow two or more cacti, Gina may plant at most one cactus in a cell.     • At most one cactus can be planted in any pair of adjacent cells. Otherwise, the cacti in those cells may be harmed by their neighbor’s thorns. Please write a program to help Gina calculate the maximum possible number of cacti can be planted, and also a way of plantings that meet the listed constraints.

HBC224036子序列,贪心,动态规划Problem G : Garden题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。

标签: HBC224036子序列 贪心 动态规划Problem G : Garden题解