/* Arrange seats: 3 a people, 3 B people, and 3 C people. It is required that three consecutive individuals cannot be of the same nationality. What is the total number of different solutions? */Public class t13 {static int sum = 0; // The total number of different schemes // check whether three public static Boolean check (char [] C) in a row exist in the same Chinese) {int COUNT = 1; // The initial number for (INT I = 0; I <C. length-1; I ++) {If (C [I] = C [I + 1]) {count ++;} else {COUNT = 1; // initial count} If (count> = 3) return true;} return false;} // all public static void Allsort (char [] C, int start, int end) {If (Start> end) {If (! Check (c) {// check whether there are three consecutive sum ++ users in the same country; // The total number of different solutions plus 1} return ;} else {for (INT I = start; I <= end; I ++) {char temp = C [I]; C [I] = C [start]; c [start] = temp; Allsort (C, start + 1, end); // recursive temp = C [I]; C [I] = C [start]; c [start] = temp ;}} public static void main (string [] ARGs) {char [] C = {'A ', 'B', 'C'}; Allsort (C, 0, C. length-1); // The system is arranged in full. out. println (SUM );}}
Running result:
283824