Description
求组合数C(n,m)
Input
T(0 < T < 2000)
每组样例两个数n, m(0 < n, m< 60)
Output
C(n,m)
Sample Input
2 1 1 2 1
Sample Output
1 2
Source
Unknown
思路:真是一道神奇的题啊,我想着用常规的办法去求解,但是爆了long long也不自知,真是傻。然后用了优化。
#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long int t, n, m; ll sum1; int main() { scanf("%d", &t); while(t--) { sum1 = 1; scanf("%d%d", &n, &m); for(int i = 1; i <= m; i++) { sum1 *= (n-i+1); sum1 /= i; } printf("%lld ", sum1); } return 0; }