일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- bfs
- join
- 깊이 우선 탐색
- Baekjoon
- 프로그래머스
- dfs
- softeer
- Dynamic Programming
- SQL 고득점 KIT
- Python
- level 3
- 동적계획법
- DP
- Java
- Lv. 0
- 너비 우선 탐색
- SQL
- group by
- javascript
- 소프티어
- 티스토리챌린지
- LEVEL 2
- Lv. 3
- 자바스크립트
- 파이썬
- 백준
- Lv. 2
- Lv. 1
- programmers
- 오블완
- Today
- Total
목록Dynamic Programming (26)
몸과 마음이 건전한 SW 개발자
문제 링크https://www.acmicpc.net/problem/11052정답 코드import sys# 입력input = sys.stdin.readlinen = int(input())cards = [0] + list(map(int, input().split())) # 계산이 쉽게 0번 인덱스 추가# 탐색dp = [0 for _ in range(n+1)]dp[1] = cards[1]for i in range(2, n+1): for j in range(1, i): dp[i] = max(dp[i-j]+dp[j], dp[i]) dp[i] = max(dp[i], cards[i])print(dp[n])풀이 방법dp 계산이 쉽게 0번 인덱스를 추가해준다.이렇게 하면 1개 일 때 cards[1..
문제 링크https://www.acmicpc.net/problem/2579정답 코드n = int(input())s = [0] * 301dp = [0] * 301for i in range(n): s[i] = int(input())dp[0] = s[0]dp[1] = s[0] + s[1]dp[2] = max(s[1] + s[2], s[0] + s[2])for i in range(3, n): dp[i] = max(dp[i - 3] + s[i - 1] + s[i], dp[i - 2] + s[i])print(dp[n - 1])풀이 방법n이 1이나 2일 때 인덱스 에러가 걸리지 않게 처음부터 크기가 301인 배열을 만든다.첫 번째 계단을 오르는 방법은 하나이므로 하나 밖에 없다.두 번째 계단을 오르는 방법..
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/136797?language=javascript 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr정답 코드function solution(numbers) { const dictLocations = { "0": [3, 1], "1": [0, 0], "2": [0, 1], "3": [0, 2], "4": [1, 0], "5": [1, 1], "6": [1, 2], "7": [2, 0], "8": [2, 1], "9": [2,..
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/138475?language=javascript 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr정답 코드function solution(e, starts) { // 각 수의 약수 개수를 저장할 배열 let dp = Array.from({ length: e + 1 }, () => 0); // 핵심 // 모든 수에 대해 약수 개수 계산 for (let i = 1; i 0); let maxCnt = 0; let ma..
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/258705# 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr정답 코드def solution(n, tops): MOD = 10007 bottomDP = [0] * n topDP = [0] * n bottomDP[0] = 1 topDP[0] = 2 + tops[0] for i in range(1, n): bottomDP[i] = (bottomDP[i - 1] + topDP[i - 1]) % MOD ..
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/118668 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr정답 코드function solution(alp, cop, problems) { let [alp_goal, cop_goal] = [0, 0]; for (const [alp_req, cop_req, alp_rwd, cop_rwd, cost] of problems) { alp_goal = Math.max(alp_goal, alp_req); cop_goal = ..