Java-MLE求助
查看原帖
Java-MLE求助
322723
NIYIKI楼主2021/2/16 10:47

源代码如下

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class Main{
	
	static StreamTokenizer scanner=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
	static PrintWriter out=new PrintWriter(System.out);
	
	static int n;	
	static int [] ans=new int[15];
	static boolean [] use=new boolean[15];	
	
	
	static void dfs(int x) {
		if(x>n) {
			for (int i = 1; i <= n; i++) {
				out.printf("%5d", ans[i]);
			}
			out.println();
			return ;
		}
		// 每个位置上可能出现的数字区间是 [1,n]
		for (int i = 1; i <=n ; i++) {
			if(!use[i]) {  // 数字 i 还未使用过的话就将其放到 x 的位置上
				ans[x]=i;
				use[i]=true;
				dfs(x+1);
				use[i]=false; // 回溯
			}
		}
	}
	
	public static void main(String[] args) throws IOException {

		n=nextInt();
		dfs(1);
		out.flush();
	}
	
	
	public static int nextInt() throws IOException {
		scanner.nextToken();
		return (int)scanner.nval;
	}
	public static double nextDouble() throws IOException{
		scanner.nextToken();
		return scanner.nval;
	}
}

测评结果如下 请问为什么会 mle

2021/2/16 10:47
加载中...