문제 링크입니다: https://programmers.co.kr/learn/courses/11133/lessons/71163
COS Pro 1급 Python 모의고사 - 보드게임
[[6, 7, 1, 2], [3, 5, 3, 9], [6, 4, 5, 2], [7, 3, 2, 6]] 38
programmers.co.kr
회사에서 COS Pro 1급을 따면 상금을 준다고 해서 재미로 풀어봤습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(board): | |
coins = [[0 for c in range(4)] for r in range(4)] | |
for i in range(4): | |
for j in range(4): | |
if i == 0 and j == 0: | |
coins[i][j] = board[i][j] | |
elif i == 0 and j != 0: | |
coins[i][j] = board[i][j] + coins[i][j-1] | |
elif i != 0 and j == 0: | |
coins[i][j] = board[i][j] + coins[i-1][j] | |
else: | |
coins[i][j] = board[i][j] + max(coins[i - 1][j], coins[i][j-1]) | |
answer = coins[3][3] | |
return answer | |
# 아래는 테스트케이스 출력을 해보기 위한 코드입니다. 아래에는 잘못된 부분이 없으니 위의 코드만 수정하세요. | |
board = [[6, 7, 1, 2], [3, 5, 3, 9], [6, 4, 5, 2], [7, 3, 2, 6]] | |
ret = solution(board) | |
# [실행] 버튼을 누르면 출력 값을 볼 수 있습니다. | |
print("solution 함수의 반환 값은", ret, "입니다.") |

개발환경: Programmers IDE
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'Python > COS Pro 1급 Python 모의고사' 카테고리의 다른 글
[Programmers] 꽃피우기 (3) | 2022.05.11 |
---|---|
[Programmers] 카드셔플 (0) | 2022.05.11 |
[Programmers] 종이접기 (0) | 2022.05.11 |
[Programmers] 아르바이트,판매사원 (0) | 2022.05.11 |
[Programmers] Up and down (0) | 2022.05.11 |