Problem AL: ACM CLUB party
Time limit: 1 Sec Memory Limit: 32 MB
submitted: 140 solved: 31
Title Description
ACM CLUB members more and more, to this end, ACM CLUB would like to prepare a party for members, evening performances by the members. The news came out, a lot of performances to sign up members, up to N, but due to limited space and time, only individuals selected from N M number, how many choices there are a method to ask?
Entry
A first data line T is a positive integer, the next set of data with a T, each data per line.
Each set of data contains two integers N (number of people to sign up, 1 <= N <= 30 ), M ( number of required program 0 <= M <= 30) .
Export
The data output of each group an integer, each output per line.
Sample input Copy
5 3 2 5 3 4 4 3 6 8 0
Sample output Copy
3 10 1 0 1
Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
//longlong 在此情况下也有可能会溢出,所以必须选择一个较小值来进行排列组合,进行运算优化
unsigned long long find(int a,int b){
unsigned long long m=1,n=1;
for (int i = 1; i <=b; i++)
{
m*=a;
a--;
n*=i;
}
unsigned long long cc=m/n;
return (cc);
}
int main(){
int num;
int a,b;
cin>>num;
getchar();
if(num>0){
while(num--){
cin>>a>>b;
getchar();
if(a>=1&&b>=0&&a<=30&&b<=30){
if(a<b){
cout<<0;
if(num!=0){
cout<<endl;
}
}
else{
if(b==0||a==b){
cout<<1;
if(num!=0){
cout<<endl;
}
continue;
}
int temp=b>(a-b)?(a-b):b;
unsigned long long c=find(a,temp);
cout<<c;
if(num!=0){
cout<<endl;
}
}
}
}
}
}