Question: In this problem, three missionaries and three cannibals must cross a river using a boat which can carry at most two people, under the constraint that, for both banks, that the missionaries present on the bank cannot be outnumbered by cannibals. The boat cannot cross the river by itself with no people on board.
First let us consider that both the missionaries (M) and cannibals(C) are on the same side of the river.
Initially the positions are : 0M , 0C and 3M , 3C (B)
Now let’s send 2 Cannibals to left of bank : 0M , 2C (B) and 3M , 1C
Send one cannibal from left to right : 0M , 1C and 3M , 2C (B)
Now send the 2 remaining Cannibals to left : 0M , 3C (B) and 3M , 0C
Send 1 cannibal to the right : 0M , 2C and 3M , 1C (B)
Now send 2 missionaries to the left : 2M , 2C (B) and 1M . 1C
Send 1 missionary and 1 cannibal to right : 1M , 1C and 2M , 2C (B)
Send 2 missionaries to left : 3M , 1C (B) and 0M , 2C
Send 1 cannibal to right : 3M , 0C and 0M , 3C (B)
Send 2 cannibals to left : 3M , 2C (B) and 0M , 1C
Send 1 cannibal to right : 3M , 1C and 0M , 2C (B)’
Send 2 cannibals to left : 3M , 3C (B) and 0M , 0C
• Here (B) shows the position of the boat after the action is performed.
Therefore all the missionaries and cannibals have crossed the river safely.
This article is contributed by kaushik. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Sum and Product of minimum and maximum element of an Array
- Sum and Product of maximum and minimum element in Binary Tree
- Sum and Product of minimum and maximum element of Binary Search Tree
- Sum and product of k smallest and k largest prime numbers in the array
- Sum and product of k smallest and k largest composite numbers in the array
- Difference between Stop and Wait, GoBackN and Selective Repeat
- Difference and similarities between HashSet, LinkedHashSet and TreeSet in Java
- What are the differences and Similarities Between Lumen and Laravel?
- Generate an array of given size with equal count and sum of odd and even numbers
- Maximum Bitwise AND pair (X, Y) from given range such that X and Y can be same
- Building a terminal based online dictionary with Python and bash
- Longest repeating and non-overlapping substring
- Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())
- Print all prime factors and their powers
- Binary Indexed Tree : Range Update and Range Queries
- strtok() and strtok_r() functions in C with examples
- Count substrings with same first and last characters
- Basic SQL Injection and Mitigation with Example
- Measuring 6L water from 4L and 9L buckets
- Bloom Filters - Introduction and Python Implementation