
package test;
import java.io.IOException;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
for (int k = 0; k < test; k++) {
int s = sc.nextInt();
int p = sc.nextInt();
int count=0;
int max=0;
int[][] array = new int[s][s];
for (int i = 0; i < s; i++) {
for (int j = 0; j < s; j++) {
array[i][j] = sc.nextInt();
}
}
for (int i = 0; i < s-p+1; i++) {
for (int j = 0; j < s-p+1; j++) {
int sum=0;
for(int x=0;x<p;x++ ) {
for(int z=0;z<p;z++ ) {
sum+=array[i+x][j+z];
}
}
if(max<sum) {
max=sum;
}
}
}
System.out.println("#"+(k+1)+" "+max);
}
}
}
1. 배열크기와 배열의 값을 입력받는다.
2. 5의 배열에 2의 파리채면 가로/세로4번씩 반복된다. 그래서 s-p+1로 했다.
3. 파리채의 수의 합을 더해준다.
4. 합을 비교해준다.
'알고리즘(종합) > Lv.2' 카테고리의 다른 글
Softeer - 8단 변속기 (0) | 2023.02.17 |
---|---|
프로그래머스 - 귤 고르기 (0) | 2023.02.15 |
1204 - 최빈수 구하기 (0) | 2022.11.14 |
1954 - 달팽이 숫자 (0) | 2022.11.13 |
1926 - 간단한 369 게임 (0) | 2022.11.13 |