import java.util.*; public class PermutationSeating2 { // We'll use a global to count the number of permutations. static int count; public static void main (String[] argv) { // Test case 1: M=3, K=2. int numSeats = 3; int numPeople = 2; int[] seats = new int [numSeats]; count = 0; printPermutations (numSeats, numPeople, seats, 1); System.out.println (" => " + count + " permutations"); // Test case 1: M=5, K=2. numSeats = 5; numPeople = 2; seats = new int [numSeats]; count = 0; printPermutations (numSeats, numPeople, seats, 1); System.out.println (" => " + count + " permutations"); } static void printPermutations (int numSpaces, int numRemaining, int[] seats, int person) { // Bottom-out case. Note that we are printing here, since each time // we get here we complete one permutation. if (numRemaining == 0) { // Print. System.out.println ( Arrays.toString(seats) ); // Remember to increment the number of permutations found. count ++; return; } // Otherwise, non-base case: look for an empty spot for "person" for (int i=0; i