A blog to see an algorithm, with Java implementation of a
Algorithm Description:
Algorithm Description: When n is greater than 2 o'clock, the total number of n is in total (2^n)-1 kinds.
When all n elements are combined, a binary number of n bits can be used to represent the extraction.
1 indicates that the bit is taken and 0 is not taken. For example, the ABC three elements of the full combination, 100 means take a,010 to take the b,001 representation take the c,101 representation to take the AC 110 to take the ab,011 representation take the bc,111 to take the ABC
Notice that the binary number representing the extraction is actually a decimal number from 1 to 7.
Generalized to a full array of n elements, with all binary forms from 1 to 2^n-1
To get 2^n, just move the 0xFFFFFFFF left 32-n bit, then right back to it.
Algorithm implementation:
Packagecom.set.test; Public classSettest { Public Static voidMain (string[] args) {String str[]= {"A", "B", "C", "D", "E" }; intncnt =str.length; intNBit = (0xFFFFFFFF >>> (32-ncnt)); for(inti = 1; I <= nBit; i++) { for(intj = 0; J < ncnt; J + +) { if((I << (31-j)) >> 31 = =-1) {System.out.print (str[j]); }} System.out.println (""); } }}
High-efficiency, full-set method (Java version implementation)