I'm not a mathematician or anything of the like, so please forgive me if I'm not using the correct terminology for something.
The problem is as follows:
Given a rectangular grid that has $m*n$ tiles, where $m$ is the amount of rows and $n$ is the amount of columns in the grid, and knowing that:
- $1 \leq m \leq 100$
- $1 \leq n \leq 100$
- Every tile is classified as either water or land
- The grid can have any amount of water tiles ranging from $0$ to $m*n$
- A shore tile is defined as any land tile that has at least 1 of its 4 (or 3 on the edges, or 2 on the corners) adjacent tiles as a water tile
What is the maximum amount of shore tiles a grid can have (I'll call it $R$)?
I started working on this by first trying to solve for very small grids and go up from there, so, for a 1x1 grid, $R = 0$, since there can't be any adjacent tile to that single tile.
W: water tile
L: land tile
$s$: amount of shore tiles
Then, for 1x2 grids:
| WW | WL | LL |
|---|---|---|
| $s=0$ | $s=1$ | $s=0$ |
So, for 1x2 (and 2x1) grids, $R = 1$
For 1x3 grids:
| WWW | WWL |
|---|---|
| $s=0$ | $s=1$ |
(ignoring some other possibilities with 1 L, because I'm interested in the maximum value, and $s$ can't be higher than the amount of L in the grid)
| WLL | LWL | LLL |
|---|---|---|
| $s=1$ | $s=2$ | $s=0$ |
So, for 1x3 (and 3x1) grids, $R = 2$
(...)
For 2x3 grids:
| WWW WWW |
WWW WWL |
WWW WLL |
WWW LLL |
WWL LLL |
LWL LWL |
WLL LLL |
LWL LLL |
LLL LLL |
|---|---|---|---|---|---|---|---|---|
| $s$=0 | $s$=1 | $s$=2 | $s$=3 | $s$=3 | $s$=4 | $s$=2 | $s$=3 | $s$=0 |
(with only 2 rows or columns, $s \leq 3*\text{amount of W's}$, and reaching the maximum has been confirmed to be possible here)
So, for 2x3 (and 3x2) grids, $R = 4$
|m \ n|1|2|3|4|5|6|
|-----|-|-|-|-|-|-|
| 1 |0|1|2|2|3|4|
| 2 |1|2|4|?|?|?|
| 3 |2|4|?|?|?|?|
| 4 |2|?|?|?|?|?|
| 5 |3|?|?|?|?|?|
| 6 |4|?|?|?|?|?|
So, up until now $$R = m*n - 1 - \lfloor m*n/4 \rfloor$$ But this is likely not a general formula (right?).
Is there a known general solution for mxn grids? And if so, is there an easier way for getting to it than what I'm doing?
Edit: reduced amount of examples, tried to fix the table at the end.
Edit 2: since it seems like the preview and the actual table don't match, I'll leave the table preformatted for now.



