private static void generatePermutations(int currentStep, int lastStep, int accumulatedSum) {

        if (accumulatedSum >= minimumSum) {
            return;
        }

        if (currentStep == lastStep) {
            accumulatedSum += cost[permutation[lastStep - 1]][permutation[0]];
            if (accumulatedSum < minimumSum) {
                minimumSum = accumulatedSum;
                System.arraycopy(permutation, 0, minimumPermutation, 0, permutation.length);
            }
            System.out.println(Arrays.toString(permutation));
        } else {
            for (int i = 0; i < lastStep; i ++) {
                if (picked[i] == false) {
                    int travelCost = currentStep == 0 ? 0 : cost[permutation[currentStep - 1]][i];
                    if (travelCost >= 0) {
                        picked[i] = true;
                        permutation[currentStep] = i;
                        generatePermutations(currentStep + 1, lastStep, accumulatedSum + travelCost);
                        picked[i] = false;
                    }
                }
            }
        }

    }