Hint please
asdasdas try to use each rule's description. Example: if heads are odd number, we can NEVER kill the dragon since cutting one-by-one doesn't change the head count, and cutting two-by-two, yes, decreases the count ttwo-by-two, but since the number is odd, that odd can never be cut.
This was just an example, try to combine each rule and their "affect to the count of N/M" to solve the problem.
Btw it's a math problem, no dynamic programming or matrix