본문 바로가기

TIL/알고리즘 문제

파리 잡기

T = int(input())
for testcase in range(1, T + 1):

	input_NM = input()
	input_N, input_M = map(int, input_NM.split())
	result = 0
	
	N = []
	for input_num in range(input_N):
		N.append([])
		N[input_num].extend(list(map(int,input().split())))

	for N_row in range(input_N - input_M + 1):
		for N_col in range(input_N - input_M + 1):
			M_sum = 0

			for M_row in range(N_row, N_row + input_M):
				for M_col in range(N_col, N_col + input_M):
					M_sum += N[M_row][M_col]
					
					if M_sum > result:
						result = M_sum
	print(f"#{testcase} {result}")

'TIL > 알고리즘 문제' 카테고리의 다른 글

1, 2, 3 더하기 문제 / 메모이제이션, 타뷸레이션 활용  (0) 2024.03.12
백준-10799 쇠막대기  (0) 2024.03.10
동전0 // 시간 복잡도  (0) 2024.03.05
소인수분해  (0) 2024.03.05
달팽이 숫자  (0) 2024.03.05