解题思路:
用递归求出总共有多少种可行的情况,再用全排列来求出总情况
注意事项:
参考代码:
#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语言代码)记得sum的归零时机浏览:928 |
IP判断 (C++代码)浏览:677 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:653 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:577 |
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:567 |
大家好,我是验题君浏览:577 |
简单的a+b (C语言代码)浏览:582 |
简单的a+b (C语言代码)浏览:531 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1479 |
大神老白 (C语言代码)浏览:601 |