内存超限了!!!求大佬!
查看原帖
内存超限了!!!求大佬!
863501
404744496xh楼主2022/12/19 19:39
import java.util.Scanner;
public class Main {
    static int[] box=new int[10];
    static boolean[] book=new boolean[10];
    static int n;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        dfs(1);

    }

    public static void dfs(int step){
        if(step==n+1){
            for(int j=1;j<=n;j++){
                System.out.printf("%5d",box[j]);
            }
            System.out.println();
        }

        for(int i=1;i<=n;i++){
            if(!book[i]){
                box[step]=i;
                book[i]=true;
                dfs(step+1);
                book[i]=false;
            }
        }

    }
}
2022/12/19 19:39
加载中...