Impostor_Syndrome's blog

By Impostor_Syndrome, history, 2 years ago, In English

We have three containers whose capacities are m litres, n litres, and p litres respectively (assume m > n > p). The n-litre and p-litre containers start out full of water, but the m-litre container is initially empty. We are allowed one type of operation: pouring the contents of one container into another, stopping only when the source container is empty or the destination container is full. We want to find the smallest sequence of pourings (if it exists) that leaves exactly x litres in the n-litre or p-litre container where (x ≤ p). If there are multiple smallest sequences, output any one of them.

How to model this question as a graph problem?

My approach
| Write comment?