public static int jump(int[] river) {
        List<Map<Integer, Integer>> states = new ArrayList<Map<Integer, Integer>>();
        int min = Integer.MAX_VALUE;

        for (int i = 0; i < river.length; i++) {
            states.add(new HashMap<Integer, Integer>());
        }
        states.get(0).put(1, 0);
        for (int i = 0; i < river.length; i++) {
            for (int speed : states.get(i).keySet()) {
                for (int j = 0; j < 2; j++) {
                    int nextStep = speed + i + j;
                    int step = states.get(i).get(speed) + 1;

                    if (nextStep >= river.length) {
                        min = Math.min(min, step);
                    } else if (river[nextStep] == 1) {
                        states.get(nextStep).put(speed + j, step);
                    }
                }
            }
        }
        return min;
    }