条件:相邻两个颜色不一样,求有多少种排序。
利用递归调用
import java.util.Scanner;
/**
* @author shkstart
*/
public class test2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int[] boo=new int[3];
int totl=0;
for (int i = 0; i < 3; i++) {
boo[i]=sc.nextInt();
totl+=boo[i];
}
System.out.println(test2.geShu(boo,0,-1,totl));
}
public static void paiXu(int n,int m,int k){
}
public static int geShu(int[] boo, int len, int last ,int totl){
if(totl==len){
return 1;
}
int count=0;
for (int i = 0; i < 3; i++) {
if(i!=last&&boo[i]>0){
boo[i]--;
count+=geShu(boo,len+1,i,totl);
boo[i]++;
}
}
return count;
}
}