计算组合数 (sdut oj)
来源:互联网 发布:mba有用吗 知乎 编辑:程序博客网 时间:2024/05/21 09:29
计算组合数
Time Limit: 1000MS Memory Limit: 32768KB
Problem Description
计算组合数。C(n,m),表示从n个数中选择m个的组合数。
计算公式如下:
若:m=0,C(n,m)=1
否则, 若 n=1,C(n,m)=1
否则,若m=n,C(n,m)=1
否则 C(n,m) = C(n-1,m-1) + C(n-1,m).
Input
第一行是正整数N,表示有N组要求的组合数。接下来N行,每行两个整数n,m (0 <= m <= n <= 20)。
Output
输出N行。每行输出一个整数表示C(n,m)。
Example Input
3
2 1
3 2
4 0
Example Output
2
3
1
Hint
Author
参考代码
#include<stdio.h>int f(int n,int m){ int y; if(m == 0) { y = 1; } else { if(n == 1) { y = 1; } else { if(m == n) { y = 1; } else { y = f(n - 1, m - 1) + f(n - 1, m); } } } return y;}int main(){ int t; int n,m; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); printf("%d\n",f(n,m)); } return 0;}
0 0
- 计算组合数 (sdut oj)
- 计算组合数 (sdut oj)
- 计算组合数C(n,m)(SDUT 2241)
- 简单计算 (sdut oj)
- 鞍点计算 (sdut oj)
- SDUT 组合数
- 优越数 (sdut oj)
- 平方数 (sdut oj)
- 水仙花数 (sdut oj)
- 计算球体积 (sdut oj)
- 求实数绝对值 (sdut oj)
- 删数问题 (sdut oj)
- 南阳OJ 组合数
- SDUT 2241-计算组合数C(n,m)(递推)
- 第X大的数 (sdut oj)
- 第X大的数 (sdut oj)
- 组合数计算技巧
- 计算组合数
- 高中数学? (sdut oj)
- 微信小程序维护登录态与获取用户信息_0
- eclipse从SVN检出maven web项目
- HDU-3397-Sequence operation
- Linux相关文章索引(3)
- 计算组合数 (sdut oj)
- 快速理解 FastCGI、PHP-CGI、PHP-FPM
- 1069.The Black Hole of Numbers (20)
- graph Laplacian 拉普拉斯矩阵
- 感知机
- 补间动画调用了VIEW哪些函数?
- 我为什么不看好微信小程序
- hdu 1860
- 我为什么不看好微信小程序_0