解题思路:
用递归求出总共有多少种可行的情况,再用全排列来求出总情况
注意事项:
参考代码:
#include <stdio.h>
int fact(int a)
{
int i, sum = 1;
for (i = 2;i <= a;i++)
sum *= i;
return sum;
}
int computer(int total, int one, int two, int x, int y)
{
if (y > x)
return 0;
else
{
if (x + y == total)
return 1;
else if (x == one&&y != two)
return computer(total, one, two, x, y + 1);
else if (x != one&&y == two)
return computer(total, one, two, x + 1, y);
else
return computer(total, one, two, x + 1, y) + computer(total, one, two, x, y + 1);
}
}
int main(void)
{
int one, two, total, count, sum;
while (scanf("%d%d%d", &total, &one, &two) != EOF)
{
if (one == 0)
sum = 0;
else
{
count = computer(total, one, two, 1, 0);
sum = count*fact(one)*fact(two);
}
printf("%d\n", sum);
}
return 0;
}
0.0分
0 人评分
C语言训练-排序问题<1> (C语言代码)浏览:601 |
蛇行矩阵 (C语言代码)浏览:753 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:465 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:2092 |
Cylinder (C语言描述,蓝桥杯)浏览:1247 |
出圈】指针malloc版浏览:355 |
杨辉三角 (C语言代码)浏览:484 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:402 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1000 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:526 |