#include<iostream.h>
int fun(int n,int m){
int s1=1,s2=1,s3=0,i,j;
for(i=0;i<m;i++){
s1*=n--;
}
for(j=m;j>=1;j--){
s2*=m--;
}
s3=s1/s2;
return s1/s2;
}
void main(){
int s=0,i,j,k,g=0,a[10]={0},b[20]={1,2,3,4,5,6,7,8,9,10,11,12},m=6,n=12;
i=1;
a[i]=1;
while(1){
if(i<m){
i++;
a[i]=a[i-1]+1;
}
if(i==m&&a[i]<n){
for(j=1;j<=m;j++){
cout<<b[a[j]-1]<<" ";
}
cout<<endl;
s++;
a[i]++;
}
if(a[i]==n){
for(int j=1;j<=m;j++){
cout<<b[a[j]-1]<<" ";
}
cout<<endl;
s++;
}
if(s==fun(n,m)){
cout<<"Total:"<<fun(n,m)<<endl;
break;
}
while(i==m&&a[i]==n){
i--;
while(a[i]==n-(m-i))
i--;
a[i]++;
}
}
}
组合C(m,n)
最新推荐文章于 2021-08-15 13:16:05 发布