A=[1,2,3]
B=[4,5,6]
C=[7,8,9] 
我对A B C三个数组进行排列组合产生新的数组,利用递归的思想很容易实现,即A B形成新数组[[1,4],[1,5],[1,6],[2,4],[2,5],[2,6],.....],然后在将这个数组与C产生我最后想要的新数组,很容易知道最终会有3*3*3=27个数组元素,如[[1,4,7],[1,4,8],[1,4,9],[1,5,7],......]。
我想问的是这里仅有3个数组,且没个数组中元素个数为3,最后产生的解为3^3=27,如果我有10个数组,且每个数组中的元素个数为100,那么就会产生100^10个元素,无法存储,eclipse会报gc overhead limit exceeded错误,因为采用递归的原因,所以每两个数组结合都会需要前一个数组的元素,所以对最后一次性存储有困难,求大神指教,跪谢!

解决方案 »

  1.   

    不知道楼主的程序是如何实现的,不过貌似不需要记录上一次的全部排列结果。public class PailieZuhe {

    public static void main(String[] args){
    int[][] m = new int[10][100];
    int count = 1;
    for(int i = 0; i < 10; i ++){
    for(int j = 0; j < 100; j ++){
    m[i][j] = count;
    count ++;
    }
    }
    pailie(m, 0, 10, 0, 100, "");
    }

    public static void pailie(int[][] a, int xbegin, int xend, int ybegin, int yend, String t){
    if(xbegin < xend){
    for(int j = ybegin; j < yend; j ++){

    pailie(a, xbegin + 1, xend, ybegin, yend, t + " " + a[xbegin][j]);
    if(xbegin == xend - 1){
    System.out.print(t + " " + a[xbegin][j]);
    System.out.println();
    }
    }
    }
    }}程序有点丑陋,应该实现了楼主的全排列功能
    如果非要记录的话,那估计只能使用磁盘来存储,然后分批使用