计算组合数C(n,m)(SDUT 2241)
来源:互联网 发布:股票数据 matlab 编辑:程序博客网 时间:2024/06/06 17:08
计算组合数C(n,m)
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
C(n,m)=n!/(m! * (n-m)!).(0<=n,m<=10^8且m<=n,该题结果保证在int范围之内)。
Input
第一行是一个正整数t,下面t行每行有两个整数n和m。
Output
对于每一行输入,分别对应输出组合数C(n,m)的值
Example Input
3
1 1
2 1
3 2
Example Output
1
2
3
Hint
题目链接:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2241.html
这道题很水,但是因为好长时间没有做题了,觉得有个思想还不错。
如果做这道题是硬计算阶乘,那么即使用long long也存不下,这时就可以将数学公式简化。比如:要计算n!/m!,其实就相当于计算n*(n-1)(n-2)(n-3)……*(m+1),因此就简化了计算。
AC的代码
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <string>#include <cstring>#include <algorithm>#include <vector>#include <stack>#include <queue>using namespace std;#define N 100010int main(void){ int t; scanf("%d",&t); double n,m; double i; double res; while(t--){ scanf("%lf%lf",&n,&m); res = 1; for(i = n; i > m; i--) res *= i; for(i = n-m; i >1; i--) res /= i; printf("%.0lf\n", res); } return 0;}
阅读全文
0 0
- 计算组合数C(n,m)(SDUT 2241)
- SDUT 2241-计算组合数C(n,m)(递推)
- 计算组合数C(m,n)
- 计算组合数C(n,m)
- 组合数C(n,m)的计算
- 组合数计算C(n,m)加取模情况
- 组合数C(n,m)
- 组合数算法 C(n,m)(n>=m)
- 变态组合数C(n,m)求解
- 求组合数c(n,m)
- codeforces 630~~【组合数 C(n,m)】
- 求组合数(c(m,n))
- 求组合数C(n , m)
- 大组合数(C(n,m))
- 计算组合数 (sdut oj)
- 计算组合数 (sdut oj)
- 组合C(m,n)
- C++/C组合数A(m,n)
- HDU-2159 FATE(完全背包)
- Oracle:any、all值的比较
- CQYZ_Vijos_P3090 赛车游戏
- Linux系统/etc/init.d目录和/etc/rc.local脚本
- FOR循环语句
- 计算组合数C(n,m)(SDUT 2241)
- day12今日内容介绍 1、构造方法 2、this关键字 3、super关键字
- linux 关键目录详解
- N
- Gap HDU
- 7、Oracle多表查询
- 操作系统(1)_操作系统基础
- SpringBoot 注解
- ADV-192盾神与砝码称重