. 1 Import java.util.Scanner; 2 . 3 public class composition Qiuzi problem set 2 . 4 { . 5 static void Perm ( int n-, int K) . 6 { . 7 // int NUM = 0; . 8 for ( int I = 0; I <(n-<<. 1); I ++ ) . 9 { 10 int KK = I; . 11 int NUM = 0 ; 12 is the while (KK> 0 ) // KK has been changed 13 is { 14 KK KK & = (. 1-KK); // meaning of the expression is eliminated after the end of the 1 most, the right to express the value of 15 NUM ++ ; // count the number of 1's number 16 } 17 IF (NUM == k) // if the number 1 number as num, on the outputs 1 digit 18 is { . 19 for ( int J = 0; J <n-; J ++ ) 20 is IF (! (I & (1 << J)) = 0 ) 21 is of System.out.print (J); 22 is System.out.println (); 23 is } 24 } 25 } 26 is public static void main (String [] args) 27 { 28 // the TODO method of automatically generating stubs 29 Scanner SC = new new Scanner (the System.in); 30 int n-= sc.nextInt (); // number represents n- 31 is int K = sc.nextInt (); // represents The number m 32 Perm (n-, K); 33 is } 34 is 35 }
It should be noted that point, the code number of the solution is a combination of an arbitrary number n m.
kk & (kk-1), the meaning of which is to remove the end of the expression 1, such as: & 1011 (1011-1) = 1011 = 1010 & 1010
1010&(1010-1) = 1010&1001 =1000