为什么出现运行时出错,我在eclipse里面都没报错。
查看原帖
为什么出现运行时出错,我在eclipse里面都没报错。
308995
F15219596948楼主2020/7/9 23:21

import java.util.Scanner;
public class Main {
	static int num = 0;
	public static void main(String []args) {
		Scanner input=new Scanner(System.in);
		int N = input.nextInt();
		int array [][] = new int [N+1][N+1];
		int array1 [][] = new int [N+1][N+1];
		boolean flag = true; 
		while(flag) {
			int a = Integer.parseInt(input.next());
			int a1 = Integer.parseInt(input.next());
			int a2 = Integer.parseInt(input.next());
			if(a==0&&a1==0&a2==0) {
				flag = false;
			}else {
				array[a][a1] = a2;
			}
		}
		Max(array,0,1,1,N,array1);
		System.out.println(num);
	}
	public static void Max(int [][]array,int max,int x ,int y,int N,int array1[][]) {
		int tame = 0;
		if(y==N&&x==N) {
			if(array[y][x]!=0) {
				tame = array[y][x];
				max = max+tame;
				array[y][x]=0;
				if(max != 0) {
					for(int i=1;i<=N;i++) {
						for(int j=1;j<=N;j++) {
							int t = array[i][j];
							array1[i][j] = t;
						}
					}
					for(int i=1;i<=N;i++) {
						for(int j=1;j<=N;j++) {
							if(array1[i-1][j]>array1[i][j-1]) {
								array1[i][j]=array1[i][j]+array1[i-1][j];
							}else {
								array1[i][j]=array1[i][j]+array1[i][j-1];
							}
						}
					}
				}
				array[y][x]=tame;
			}else {
				if(max != 0) {
					for(int i=1;i<=N;i++) {
						for(int j=1;j<=N;j++) {
							int t = array[i][j];
							array1[i][j] = t;
						}
					}
					for(int i=1;i<=N;i++) {
						for(int j=1;j<=N;j++) {
							if(array1[i-1][j]>array1[i][j-1]) {
								array1[i][j]=array1[i][j]+array1[i-1][j];
							}else {
								array1[i][j]=array1[i][j]+array1[i][j-1];
							}
						}
					}
				}
			}
			num = Math.max(num, (max+array1[N][N]));
			return ;
		}
		if(x<N) {
			if(array[y][x] != 0) {
				tame = array[y][x];
				max = max + tame;
				array[y][x] = 0;
				Max(array,max,x+1,y,N,array1);
				max = max-tame;
				array[y][x] = tame;
			}else {
				Max(array,max,x+1,y,N,array1);
			}
		}
		if(y<N) {
			if(array[y][x] != 0) {
				tame = array[y][x];
				max = max + tame;
				array[y][x] = 0;
				Max(array,max,x,y+1,N,array1);
				max = max-tame;
				array[y][x] = tame;
			}else {
				Max(array,max,x,y+1,N,array1);
			}
		}
		return;
	}
}
2020/7/9 23:21
加载中...