public List<List<Integer>> subsets(int[] S) {
		List<List<Integer>> ret = new ArrayList<List<Integer>>();

		quickSort(S);

		int length = S.length;
		int[] index = new int[length];
		for (int i = 0; i < length; i++) {
			index[i] = 0;
		}

		int currTurnLength = 0;
		int eleHave = 0;
		int lastTurnIndex = 0;
		while (currTurnLength++ < length) {
			eleHave = 0;
			lastTurnIndex = -1;
			while (true) {
				while (eleHave < currTurnLength) {
					lastTurnIndex++;
					index[eleHave] = lastTurnIndex;
					eleHave++;
				}

				Integer[] turnRet = new Integer[currTurnLength];
				for (int i = 0; i < currTurnLength; i++) {
					turnRet[i] = S[index[i]];
				}
				ret.add(Arrays.asList(turnRet));

				boolean found = false;
				while (eleHave-- > 0 && !found) {
					if (length - index[eleHave] > (currTurnLength - eleHave)) {
						lastTurnIndex = index[eleHave];
						found = true;
						break;
					}
				}

				if (!found) {
					break;
				}
			}
		}

		ret.add(new ArrayList<Integer>());
		return ret;
	}