Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
30
Task/Combinations/Java/combinations.java
Normal file
30
Task/Combinations/Java/combinations.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class Comb{
|
||||
|
||||
public static void main(String[] args){
|
||||
System.out.println(comb(3,5));
|
||||
}
|
||||
|
||||
public static String bitprint(int u){
|
||||
String s= "";
|
||||
for(int n= 0;u > 0;++n, u>>= 1)
|
||||
if((u & 1) > 0) s+= n + " ";
|
||||
return s;
|
||||
}
|
||||
|
||||
public static int bitcount(int u){
|
||||
int n;
|
||||
for(n= 0;u > 0;++n, u&= (u - 1));//Turn the last set bit to a 0
|
||||
return n;
|
||||
}
|
||||
|
||||
public static LinkedList<String> comb(int c, int n){
|
||||
LinkedList<String> s= new LinkedList<String>();
|
||||
for(int u= 0;u < 1 << n;u++)
|
||||
if(bitcount(u) == c) s.push(bitprint(u));
|
||||
Collections.sort(s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue