View Code of Problem 65

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {	
		Scanner scan = new Scanner(System.in);
		int count = scan.nextInt();
		int num;
		for(int i=0;i<count;i--) {
			num = scan.nextInt();
			int[][] a = new int[num][num];
			for(int j=0;j<num;j++) {
				for(int k=0;k<=j;k++) {
					a[j][k] = scan.nextInt();
				}
			}
			for(int j=num-2;j>=0;j--) {
				for(int k=0;k<=j;k++) {
					a[j][k] += Math.max(a[j+1][k], a[j+1][k+1]);
				}
			}
			System.out.println(a[0][0]);
		}
			
		scan.close();
		}
}

Double click to view unformatted code.


Back to problem 65