import java.util.*; public class PSBitSet { public static void powerSet(int n){ BitSet C = new BitSet(n); BitSet P = new BitSet(n); P.set(0,n,true); powerSet(C,P); } private static void powerSet(BitSet C,BitSet P){ if (P.isEmpty()){System.out.println(C); return;} int v = P.nextSetBit(0); BitSet C_new = (BitSet)C.clone(); BitSet P_new = (BitSet)P.clone(); C_new.set(v,true); P_new.set(v,false); powerSet(C_new,P_new); // take powerSet(C,P_new); // don't take } public static void main(String[] args) { int n = Integer.parseInt(args[0]); powerSet(n); } } // // powerSet performs a bifurcating search for the power set with // all sets occuring at depth n. At depth d we have 2^d states. // In total 2^(n+1) - 1 states are visited //