Eating Lions, Wolves, and Goats Faster
strilanc.com
strilanc.com
If you want to enumerate stable forests, you only need to know the largest pure lion/goat/wolf forests. You get all the other stables one by repeatedly subtracting 2 from those. Takes linear time to yield everything, and constant space.
If you want to enumerate all reachable forests, stable or not, you just do a triple loop over how many times to apply each operation and yield the results. The results you get won't overlap because the operations are linearly independent. Takes cubic time to yield everything, but only constant space.
1: http://www.unisoftwareplus.com/download/blog/2014-06/magicFo...
Rewriting the solution to use a single long smashes the C++ too but yet again, it feels horrid when the real solution is O(1)...
Then have all the wolves eat goats until only one of the species is left, say 2k wolves. Then do k iterations of lion eat wolf and wolf eat goat.
As to the problem, the second I started reading I knew it would be an operations research problem. Though, to be honest I thought there would be a closed form solution