https://www.acmicpc.net/problem/11048
❗풀이방법
- 1행과 1열은 누적합 계산
- (1, 1)에서부터 DP 계산
- max(graph[i-1][j], graph[i][j-1], graph[i-1][j-1]) 계산 후 (i, j)에 합하기
❗코드
import sys
input = sys.stdin.readline
n, m = map(int, input().split(" "))
graph = []
for _ in range(n):
temp = list(map(int, input().split(" ")))
graph.append(temp)
for i in range(1, n):
graph[i][0] += graph[i-1][0]
for i in range(1, m):
graph[0][i] += graph[0][i-1]
for i in range(1, n):
for j in range(1, m):
graph[i][j] += max(graph[i-1][j], graph[i][j-1], graph[i-1][j-1])
print(graph[n-1][m-1])
728x90
반응형
'🔻PS > Baekjoon' 카테고리의 다른 글
[Baekjoon] 백준 11060 점프 점프 Python (0) | 2024.10.02 |
---|---|
[Baekjoon] 백준 1937 욕심쟁이 판다 Python (0) | 2024.10.01 |
[Baekjoon] 백준 20056 마법사 상어와 파이어볼 Python (0) | 2024.09.29 |
[Baekjoon] 백준 20922 겹치는 건 싫어 Python (0) | 2024.09.24 |
[Baekjoon] 백준 1806 부분합 Python (0) | 2024.09.23 |