一
import java
//利用二進制算法進行全排列
//count
//count
public class test {
public static void main(String[] args) {
long start=System
count
long end=System
System
}
private static void count
int[] num=new int []{
for(int i=
String str=Integer
int sz=str
for(int j=
str="
}
char[] temp=str
Arrays
String gl=new String(temp);
if(!gl
continue;
}
String result="";
for(int m=
result+=num[Integer
}
System
}
}
public static void count
int[] num=new int []{
int[] ss=new int []{
int[] temp=new int[
while(temp[
temp[temp
for(int i=temp
if(temp[i]==
temp[i]=
temp[i
}
}
int []tt=temp
Arrays
if(!Arrays
continue;
}
String result="";
for(int i=
result+=num[temp[i]];
}
System
}
}
}
二
package practice;
import java
import java
public class Test
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto
Object[] tmp={
// ArrayList<Object[]> rs=RandomC(tmp);
ArrayList<Object[]> rs=cmn(tmp
for(int i=
{
// System
for(int j=
{
System
}
System
}
}
// 求一個數組的任意組合
static ArrayList<Object[]> RandomC(Object[] source)
{
ArrayList<Object[]> result=new ArrayList<Object[]>();
if(source
{
result
}
else
{
Object[] psource=new Object[source
for(int i=
{
psource[i]=source[i];
}
result=RandomC(psource);
int len=result
result
for(int i=
{
Object[] tmp=new Object[result
for(int j=
{
tmp[j]=result
}
tmp[tmp
result
}
}
return result;
}
static ArrayList<Object[]> cmn(Object[] source
{
ArrayList<Object[]> result=new ArrayList<Object[]>();
if(n==
{
for(int i=
{
result
}
}
else if(source
{
result
}
else
{
Object[] psource=new Object[source
for(int i=
{
psource[i]=source[i];
}
result=cmn(psource
ArrayList<Object[]> tmp=cmn(psource
for(int i=
{
Object[] rs=new Object[n];
for(int j=
{
rs[j]=tmp
}
rs[n
result
}
}
return result;
}
}
三
package Acm;
//強大的求組合數
public class MainApp {
public static void main(String[] args) {
int[] num=new int[]{
String str="";
//求
// count(
// 求
count
}
private static void count
if(i==num
System
return;
}
count
count
}
private static void count(int i
if(n==
System
return;
}
if(i==num
return;
}
count(i+
count(i+
}
}
下面是求排列
package Acm;
//求排列
import java
import java
private static boolean f[];
public static void main(String[] args) {
Scanner sc=new Scanner(System
int sz=sc
for(int i=
int sum=sc
f=new boolean[sum];
Arrays
int[] num=new int[sum];
for(int j=
num[j]=j+
}
int nn=sc
String str="";
count(num
}
}
/**
*
* @param num 表示要排列的數組
* @param str 以排列好的字符串
* @param nn 剩下需要排列的個數
*/
private static void count(int[] num
if(nn==
System
return;
}
for(int i=
if(!f[i]){
continue;
}
f[i]=false;
count(num
f[i]=true;
}
}
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20148.html