dynamicprogramming

개발공부/algorithm

[프로그래머스][python] 정수삼각형 - DP

문제 프로그래머스 정수삼각형 Level 3 Link 코딩테스트 연습 - 정수 삼각형 [[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]] 30 programmers.co.kr 나의 풀이 동적계획법으로 풀면 되는 문제다. 주어진 2차원 배열의 첫 번째 배열부터 그 다음 배열에 값을 더해나가면서 저장해준다. 가장 마지막의 배열의 최대 값을 리턴해준다. # https://programmers.co.kr/learn/courses/30/lessons/43105 """ 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 """ def solution(triangle): for j in range(1, len(triangle)): for i in range(len(tr..

개발공부/algorithm

[Leetcode][python] 120: triangle - DP

Leetcode 120: Triangle Level: Medium Link Triangle - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com My Approach Sum up the previous lists values to the current list For the first element and the last element, add up the first element of the last element of the list before. Continu..

개발공부/algorithm

[백준][python]10844.쉬운계단수 - DP

백준 10844 쉬운 계단 수 Silver I 문제링크 10844번: 쉬운 계단 수 첫째 줄에 정답을 1,000,000,000으로 나눈 나머지를 출력한다. www.acmicpc.net 나의 접근 DFS 로직으로 가장 뒷자리의 숫자에 +1, -1 한 경우에 대해 깊이우선 탐색을 진행해주고 N의 길이까지 탐색을 완료하면 count를 더 해주는 식으로 구현해봤는데.. 시간초과가 났다. 아래는 해당 코드다. import sys def dfs(startnum, idx): global count change = [1, -1] if idx == N - 1: count += 1 return count for calc in range(2): newnum = startnum + change[calc] #2 if 0

so.py
'dynamicprogramming' 태그의 글 목록