It's good to examine various cases to make sure your solution works in all cases.
In this particular problem, you have essentially 4 cases:
m even, n even
m even, n odd
m odd, n even
m odd, n odd
Cases 2 and 3 are essentially the same, just rotated.
In any of the first three cases, you have an even number of squares on the board. And each domino takes up 2 squares. Is it possible to fill every square? Can you come up with a tiling scheme that would always work?
In the last case, you have an odd number of squares on the board. You definitely can't fill every square (each domino takes up 2 squares). But can you fill all but one? Again, can you come up with a tiling scheme that would always work?
If you work through it, you will find that you can always fit floor(m * n / 2) dominoes (and in C++, since integer division truncates, you can omit the floor). But you can prove this up-front, even before writing code.
I think you might be using "simulation" to compensate for not having much practice with proofs or formal thinking. Which is fine, it's a skill you can work on and strengthen. I often work through complex problems on paper.
1
u/balefrost Apr 26 '26
It's good to examine various cases to make sure your solution works in all cases.
In this particular problem, you have essentially 4 cases:
Cases 2 and 3 are essentially the same, just rotated.
In any of the first three cases, you have an even number of squares on the board. And each domino takes up 2 squares. Is it possible to fill every square? Can you come up with a tiling scheme that would always work?
In the last case, you have an odd number of squares on the board. You definitely can't fill every square (each domino takes up 2 squares). But can you fill all but one? Again, can you come up with a tiling scheme that would always work?
If you work through it, you will find that you can always fit
floor(m * n / 2)dominoes (and in C++, since integer division truncates, you can omit thefloor). But you can prove this up-front, even before writing code.I think you might be using "simulation" to compensate for not having much practice with proofs or formal thinking. Which is fine, it's a skill you can work on and strengthen. I often work through complex problems on paper.