Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Rec {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int n = scan.nextInt();
- int[][] rec = new int[n][n];
- for(int i = 0 ; i < n ; ++i) {
- for(int j = 0 ; j < n ; ++i) {
- rec[i][j] = scan.nextInt();
- }
- }
- for(int i = 1 ; i < n ; ++i) {
- for(int j = 0 ; j < n ; ++j) {
- int mx = -1;
- for(int k = 0 ; k < n ; ++k) {
- if(k != j) {
- mx = Math.max(mx, rec[i-1][k] + rec[i][j]);
- }
- }
- rec[i][j] = mx;
- }
- }
- System.out.println(findMax(rec));
- }
- private static int findMax(int[][] rec) {
- int mx = rec[rec.length - 1][0];
- for(int i = 0 ; i < rec.length ; ++i) {
- mx = Math.max(mx, rec[rec.length - 1][i]);
- }
- return mx;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement