spoj POUR1 – Pouring water

You can read the problem statement at here.

this problem can be solved using a brute-force approach i.e by doing a bfs on the states of the jars. we can also do a dfs to find a solution but since the problem asks us to find a minimum solution, we have to do bfs.

https://gist.github.com/027531207ada11d6cb31

PS: another of way solving is by using extended euclid’s theorem.(from spoj comments.)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s