티스토리 뷰

 2001. 파리 퇴치

swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PzOCKAigDFAUq&categoryId=AV5PzOCKAigDFAUq&categoryType=CODE&problemTitle=&orderBy=INQUERY_COUNT&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

import java.util.Scanner;

// 210130
// 2001. 파리 퇴치
public class SWEA2001 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int T = sc.nextInt();

		for (int tc = 1; tc <= T; tc++) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			int[][] arr = new int[N][N];

			// 입력
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					arr[i][j] = sc.nextInt();
				}
			}

			int max = 0;
			for (int i = 0; i <= (N - M); i++) {
				for (int j = 0; j <= (N - M); j++) {
					int sum = 0;
					for (int z=0; z<M; z++) {
						for (int w=0; w<M; w++) {
							sum += arr[i+z][j+w];
						}
					}
					if (sum > max) max = sum;
				}
			}
			System.out.println("#" + tc + " " + max);
		} // for

		sc.close();
	} // main
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함