Question: We have three containers whose sizes are A pints, B pints and C pints, respectively, where A , B , C are all positive integers.

We have three containers whose sizes are A pints, B pints and C pints, respectively, where A, B, C are all positive integers.
In the beginning, the A-pint container has a pints of water, the B-pint container has b pints of water, and the C-pint container
has c pints of water, where a, b and c are non-negative integers. (For example, we might have A =10, B =7, C =4 and
a =0, b =6, c =4.) 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 know if there is a sequence of pourings
that, in the end, leaves exactly k pints of water in any of the three containers. (So the answer we seek is either YES or NO.)
1) Model this problem as a graph problem: give a precise definition of the graph involved, and state the specific question
about this graph that needs to be answered.
2) Design an efficient algorithm to solve the above problem following this format: (1) explain the main idea of the algorithm, (2) present its pseudo-code, (3)
prove its correctness, (4) analyze its time complexity. It has to be most efficient time complexity.Problem 1
We have three containers whose sizes are A pints, B pints and C pints, respectively, where A,B,C are all positive integers.
In the beginning, the A-pint container has a pints of water, the B-pint container has b pints of water, and the C-pint container
has c pints of water, where a,b and c are non-negative integers. (For example, we might have A=10,B=7,C=4 and
a=0,b=6,c=4.) 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 know if there is a sequence of pourings
that, in the end, leaves exactly k pints of water in any of the three containers. (So the answer we seek is either YES or NO.)
Your task:
Model this problem as a graph problem: give a precise definition of the graph involved, and state the specific question
about this graph that needs to be answered.
Design an efficient algorithm to solve the above problem.
 We have three containers whose sizes are A pints, B pints

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!