1
|
import java.util.Scanner;
public class solution_d2_2001 { public static void main(String[] args) { // 2001 파리 퇴치 Scanner sc= new Scanner(System.in); int testcase=sc.nextInt(); for (int i=0; i<testcase; i++) { int N=sc.nextInt(); int M=sc.nextInt(); int[][] mainArr=new int[N][N]; for (int j=0; j<N; j++) { for (int k=0; k<N; k++) { mainArr[j][k]=sc.nextInt(); } } int max=0; // 가장 큰 합을 담을 변수 // 가로 세로 모두 N-M+1 번씩 탐색하게됨 for (int x=0; x< N-M+1; x++ ) { for (int y=0; y< N-M+1; y++ ) { int cnt=0; //그 안에서 M 만큼 탐색 for (int z=0; z<M; z++) { for (int t=0; t<M; t++) { cnt+=mainArr[x+z][y+t]; //이동하며 합 UPDTAE } if (max<cnt) max=cnt; // 값이 나올떄마다 최대값 구분 } } } System.out.println("#"+(i+1)+" " +max); } } } |
cs |
'Algorithm > SWEA' 카테고리의 다른 글
[SWEA] 1979: 어디에 단어가 들어갈수 있을까? (JAVA) (0) | 2022.07.05 |
---|---|
[SWEA] 1959: 두개의 숫자열 (JAVA) (0) | 2022.07.05 |
[SWEA] 2025: N줄 덧셈 (python) (0) | 2022.07.04 |
[SWEA] 2019: 더블더블 (python) (0) | 2022.07.04 |
[SWEA] 1938: 아주 간단한계산기 (python) (0) | 2022.07.04 |