Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- autoencoder
- vscode
- FastAPI
- wandb
- torchserve
- Matplotlib
- GitHub Action
- Kaggle
- leetcode
- FDS
- docker
- rnn
- GIT
- 완전탐색
- DeepLearning
- 백준
- Kubernetes
- 알고리즘
- GCP
- pytorch
- 네이버AItech
- 프로그래머스
- pep8
- github
- datascience
- 코딩테스트
- PytorchLightning
- NaverAItech
- NLP
- python
Archives
- Today
- Total
Sangmun
백준 2096번 내려가기 본문
https://www.acmicpc.net/problem/2096
2096번: 내려가기
첫째 줄에 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 숫자가 세 개씩 주어진다. 숫자는 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 중의 하나가 된다.
www.acmicpc.net
기본적인 DP문제이나 메모리 제한이 4메가 밖에 되지 않음으로 무작정 이전의 연산 결과를 저장할 리스트를 만들면 메모리 초과가 나게된다.
이점을 주의를 해서 코딩을 해주면 된다.
import sys
input = sys.stdin.readline
N = int(input())
max_matrix = [0,0,0]
min_matrix = [0,0,0]
for _ in range(N):
a, b, c = map(int,input().split())
new_a = max(a + max_matrix[0], a + max_matrix[1])
new_b = max(b + max_matrix[0], b + max_matrix[1], b + max_matrix[2])
new_c = max(c + max_matrix[1], c + max_matrix[2])
max_matrix = [new_a,new_b,new_c]
new_a = min(a + min_matrix[0], a + min_matrix[1])
new_b = min(b + min_matrix[0], b + min_matrix[1], b + min_matrix[2])
new_c = min(c + min_matrix[1], c + min_matrix[2])
min_matrix = [new_a,new_b,new_c]
print(max(max_matrix))
print(min(min_matrix))
'알고리즘 > 백준' 카테고리의 다른 글
백준 17144번 미세먼지 안녕! (0) | 2022.12.14 |
---|---|
백준 12851번 숨바꼭질2 (0) | 2022.12.14 |
백준 15686번 치킨 배달 (0) | 2022.12.12 |
백준 14938번 서강그라운드 (0) | 2022.12.10 |
백준 16953번 A -> B (0) | 2022.12.08 |
Comments