shallowcmz


私信TA

用户名:shallowcmz

访问量:41094

签 名:

行者常至,为者常成

等  级
排  名 230
经  验 6059
参赛次数 1
文章发表 57
年  龄 18
在职情况 学生
学  校 东莞理工学院
专  业 软件工程

  自我简介:

解题思路:


用递归求出总共有多少种可行的情况,再用全排列来求出总情况


注意事项:





参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区