solves the river crossing problem