1 から n1 + n2 までの n1 + n2 個の数字から n1 個を取り出す組み合わせ
#define first(n) ( (unsigned int)( ( 1U<<(n) ) - 1U ) )
void comb1(int n1,int n2)
{
int i,j,k,m[101];
unsigned int x,s;
unsigned int smallest,ripple,new_smallest,ones;
i=1; x=first(n1);
while( ! (x & ~first(n1+n2)) ) {
s=x; k=1;
for( j=1;j<=n1+n2;j++ ) {
if( s & 1 ) {
m[k]=j;
k++;
}
s >>= 1;
}
for(k=1;k<=n1;k++) printf(" %2d",m[k]);
printf("\n");
smallest = x & -x;
ripple = x + smallest;
new_smallest = ripple & -ripple;
ones = ( ( new_smallest/smallest ) >> 1 ) - 1;
x= ripple | ones;
i++;
}
}
aaa