Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- public class Main {
- public static int next_mask(int x){
- int a = x & -x;
- int b = x + a;
- int c = b ^ x;
- a <<= 2;
- c /= a;
- return b | c;
- }
- public static void main(String[] args) {
- int deep = 3;
- int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- List<int[]> list = new ArrayList<>();
- int current = (1 << deep) - 1;
- int last = 1 << array.length;
- do {
- int pos = 0;
- int index = 0;
- int[] res = new int[deep];
- for (int a = current; a != 0; a >>= 1){
- if ((a & 1) == 1) res[index++] = array[pos];
- pos++;
- }
- list.add(res);
- current = next_mask(current);
- } while (current < last);
- for (int[] k : list) System.out.println(Arrays.toString(k));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement