java中排列组合问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 22:15:13
请输出由2,4,4,6,8,9组成的所有6不在千位切8,9不相临的的六位数,并统计个数
注意:有两个4

这个程序希望能帮到你。

我的output
.....(太多了,省略)
442869
442869
424869
244869
424869
244869
Total weird numbers: 396
............permu time: 13 milliseconds..........

程序代码如下:
package test;

import java.util.Date;

/**
*
* @author liang.rao@gmail.com
* @date 16.Nov.2007
* @why zhidao.baidu.com : question/39707738.html
*
*/

public class WeirdNumbers {

public static int counter = 0;

// print N! permutation of the elements of array a (not in order)
public static void perm2(String s) {
int N = s.length();
char[] a = new char[N];
for (int i = 0; i < N; i++)
a[i] = s.charAt(i);
perm2(a, N);
}

private static void perm2(char[] a, int n) {
if (n == 1 && numberControl(a)) {
System.out.println(a);
counter++;
return;
}
for (int i = 0; i &l