/**
*
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
InLineProblem(0, 0, 12);
System.out.println("总共的排列数目为:"+totalNum);
}
static int totalNum = 0;
//函数功能 : 排队问题
//函数参数 : firstFree为第1排第1个空余位置
// secondFree为第2排第1个空余位置
// num为排队人数
//返回值 : 无
static void InLineProblem(int firstFree, int secondFree, int num)
{
if(firstFree == num/2 || secondFree == num/2) //其中一排无剩余位置
{
totalNum++;
return;
}
if(firstFree == secondFree) //第1排人数与第2排人数一样
{
InLineProblem(firstFree + 1, secondFree, num); //只能排在第1排
}
else
{
InLineProblem(firstFree + 1, secondFree, num); //排在第1排
InLineProblem(firstFree, secondFree + 1, num); //排在第2排
}
}
*
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
InLineProblem(0, 0, 12);
System.out.println("总共的排列数目为:"+totalNum);
}
static int totalNum = 0;
//函数功能 : 排队问题
//函数参数 : firstFree为第1排第1个空余位置
// secondFree为第2排第1个空余位置
// num为排队人数
//返回值 : 无
static void InLineProblem(int firstFree, int secondFree, int num)
{
if(firstFree == num/2 || secondFree == num/2) //其中一排无剩余位置
{
totalNum++;
return;
}
if(firstFree == secondFree) //第1排人数与第2排人数一样
{
InLineProblem(firstFree + 1, secondFree, num); //只能排在第1排
}
else
{
InLineProblem(firstFree + 1, secondFree, num); //排在第1排
InLineProblem(firstFree, secondFree + 1, num); //排在第2排
}
}