/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package uva100;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int i,j, max = 0;
int n = scanner.nextInt();
int arr[][] = new int[n][n];
for (i=0; i<n; i++) {
for (j=0;j<n;j++) {
arr[i][j] = scanner.nextInt();
}
}
max = arr[0][0];
for (int leftCol=0;leftCol<n;leftCol++) {
int[] tempArr = new int[n];
for (int rightCol=leftCol;rightCol<n;rightCol++) {
for (i=0;i<n;i++) {
tempArr[i] += arr[i][rightCol];
}
int maximum = maxincolumn(tempArr);
if (maximum > max) {
max = maximum;
}
}
}
System.out.println(max);
}
static int maxincolumn(int col[]) {
int max = col[0];
for (int i=0;i<col.length;i++) {
int temp = 0;
for (int j=i;j<col.length;j++) {
temp += col[j];
if (temp > max) {
max = temp;
}
}
}
return max;
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package uva100;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int i,j, max = 0;
int n = scanner.nextInt();
int arr[][] = new int[n][n];
for (i=0; i<n; i++) {
for (j=0;j<n;j++) {
arr[i][j] = scanner.nextInt();
}
}
max = arr[0][0];
for (int leftCol=0;leftCol<n;leftCol++) {
int[] tempArr = new int[n];
for (int rightCol=leftCol;rightCol<n;rightCol++) {
for (i=0;i<n;i++) {
tempArr[i] += arr[i][rightCol];
}
int maximum = maxincolumn(tempArr);
if (maximum > max) {
max = maximum;
}
}
}
System.out.println(max);
}
static int maxincolumn(int col[]) {
int max = col[0];
for (int i=0;i<col.length;i++) {
int temp = 0;
for (int j=i;j<col.length;j++) {
temp += col[j];
if (temp > max) {
max = temp;
}
}
}
return max;
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন