/*******************************************************************************
48. 将4个红球,3个白球与3个黄球排成一排,共有多少种排法?
*****************************************************************************/
#include <stdio.h>
int counter = 0;
char* color[3] = {"RED","WHITE","YELLOW"};
int count[3] = {4,3,3};
int status[3] = {0,0,0};
int perm[10];
void PutIt(int k)
{
int i;
if(k == 10)//完成
{
//output
counter++;
for(i=0; i<10; i++)
printf("%s ",color[perm[i]]);
printf("/n");
}
else
{
for(i=0; i<3; i++)
{
perm[k] = i;
++status[i];
if(status[i] <= count[i])
PutIt(k+1);
--status[i];
}
}
}
void main()
{
PutIt(0);
printf("一共有%d种排法!/n", counter);
}
练习48
最新推荐文章于 2021-02-08 22:25:01 发布