Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,25 @@
public static ArrayList<String> getpowerset(int a[],int n,ArrayList<String> ps)
{
if(n<0)
{
return null;
}
if(n==0)
{
if(ps==null)
ps=new ArrayList<String>();
ps.add(" ");
return ps;
}
ps=getpowerset(a, n-1, ps);
ArrayList<String> tmp=new ArrayList<String>();
for(String s:ps)
{
if(s.equals(" "))
tmp.add(""+a[n-1]);
else
tmp.add(s+a[n-1]);
}
ps.addAll(tmp);
return ps;
}

View file

@ -0,0 +1,23 @@
public static <T> List<List<T>> powerset(Collection<T> list) {
List<List<T>> ps = new ArrayList<List<T>>();
ps.add(new ArrayList<T>()); // add the empty set
// for every item in the original list
for (T item : list) {
List<List<T>> newPs = new ArrayList<List<T>>();
for (List<T> subset : ps) {
// copy all of the current powerset's subsets
newPs.add(subset);
// plus the subsets appended with the current item
List<T> newSubset = new ArrayList<T>(subset);
newSubset.add(item);
newPs.add(newSubset);
}
// powerset is now powerset of list.subList(0, list.indexOf(item)+1)
ps = newPs;
}
return ps;
}

View file

@ -0,0 +1,16 @@
public static <T extends Comparable<? super T>> LinkedList<LinkedList<T>> BinPowSet(
LinkedList<T> A){
LinkedList<LinkedList<T>> ans= new LinkedList<LinkedList<T>>();
int ansSize = (int)Math.pow(2, A.size());
for(int i= 0;i< ansSize;++i){
String bin= Integer.toBinaryString(i); //convert to binary
while(bin.length() < A.size()) bin = "0" + bin; //pad with 0's
LinkedList<T> thisComb = new LinkedList<T>(); //place to put one combination
for(int j= 0;j< A.size();++j){
if(bin.charAt(j) == '1')thisComb.add(A.get(j));
}
Collections.sort(thisComb); //sort it for easy checking
ans.add(thisComb); //put this set in the answer list
}
return ans;
}