A person must cross the dog, a chicken and a cabbage, and the ship can only bring the same thing every time, ask how to transport the chicken without eating cabbage and dogs Don't eat a chicken?
Tip: We use a four-dimensional vector with a four-dimensional vector. When an object is on the shore, the corresponding component is 1, otherwise 0. Such as: (1, 0, 1, 0) indicate people and chickens on this shore and call it into a state. According to the meaning of the title (1, 0, 1, 0) is a permissible state, and (0, 0, 1, 1) is an unauthorized state.
We use S to remember all permissible states: (1, 1, 1, 10) (1, 1, 1, 0), (0, 0, 0, 1) (1) 1, 10, 1), (0, 10, 1, 1), (0, 1, 0, 0) (1, 0, 1, 0), (0, 1 0, 1)
We also use a four-dimensional vector, such as (1, 1, 0, 0) representing a person, a dog on a boat, such that the permissible state D has a total of 4: (1, 1, 0, 0) (1, 0, 1, 10), (1, 0, 0, 0)
We specify that the elements in S and D are added to the binary law, and the river is a state and the addition of the other state. We add (1, 1, 1, 1) to each of the four vectors of D, if It is the allowed state, then each allowed state continues to add four vectors in D until (0, 0, 0, 0) is to, if it is not allowed, the vector stops calculation.
I wrote an algorithm to calculate the need for several times to the river to go smoothly: public class test {public static void main (string [] args) {int [] [] State1 = {{1, 1, 0, 0}, { 1, 0, 1, 10}, {1, 0, 0, 10}}; int [] [] state2 = {{1, 1, 1, 1}, {1 1, 1, 0}, {1,0,1,1}, {1,0,1,0}, {0, 0, 0, 0}, {0 , 0, 0, 1, 0}, {0, 1, 0, 0}, {0, 1, 0, 1}}; int [] [] a = new int = ] [4]; int [] [] b = new int [100] [4]; int [] result = new int [4]; int [] Correct = {0, 0, 0, 0}; for (int i = 0; i <4; i ) a [0] [i] = 1; int ROWS = 1; int ANSWER = 0; while (true) {int ROWS2 = 0; Answer ; for (int i = 0; i