# Seats should be arranged: Three Chinese a people, three Chinese B people, and three Chinese C people sit in a row. It is required that three consecutive individuals cannot be of the same nationality.

Source: Internet
Author: User
`/* 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`

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.