Problem Description
开学了,杭电又迎来了好多新生。ACMer想为新生准备一个节目。来报名要表演节目的人很多,多达N个,但是只需要从这N个人中选M个就够了,一共有多少种选择方法?
Input
数据的第一行包括一个正整数T,接下来有T组数据,每组数据占一行。 每组数据包含两个整数N(来报名的人数,1<=N<=30),M(节目需要的人数0<=M<=30)
Output
每组数据输出一个整数,每个输出占一行
Sample Input
5 3 2 5 3 4 4 3 6 8 0
Sample Output
3 10 1 0 1
//第一遍,wa了。。。是int冒了的缘故
1 #include2 3 using namespace std; 4 int a,b; 5 double zh(int a,int b) 6 { 7 int up=1,down=1; 8 for(int i=1;i<=b;i++) 9 {up=up*a;a--;}10 for(int i=1;i<=b;i++)11 down=down*i;12 return up/down;13 }14 15 int main()16 {17 int i;18 cin>>i;19 while(i--)20 {21 cin>>a>>b;22 cout< <
//第二遍。。采用一边算一边除的方法。。。
//自己好弱啊!!!又错了。。。//有点意思(去死
1 #include2 #include 3 using namespace std; 4 long long a,b; 5 double zh(long long a,long long b) 6 { 7 double ans=1.0; 8 long long j=b; 9 while(j--)10 {11 ans=ans*a/b;12 a--;b--;13 }14 return ans;15 }16 17 18 int main()19 {20 int n;21 cin>>n;22 while(n--)23 {24 cin>>a>>b;25 cout< <
//错误点。。。double不能cout,,,应该printf
#include#include using namespace std;long long a,b;double zh(long long a,long long b){ double ans=1.0; long long j=b; while(j--) { ans=ans*a/b; a--;b--; } return ans;}int main(){ int n; cin>>n; while(n--) { cin>>a>>b; printf("%.0lf\n",zh(a,b)); } return 0;}