IT/알고리즘 13

[프로그래머스 Python] 호텔 대실

Level 2https://school.programmers.co.kr/learn/courses/30/lessons/155651 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krimport heapqdef chg_time(x, s): h, m = map(int, x.split(":")) if s: #체크아웃 if m+10 >= 60: #청소기간 더해주기 h+=1 m-=50 else: m+=10 return h*100+mdef solution(book_time): answer = 0 book_tim..

IT/알고리즘 2025.02.23

[백준 Python] 1717번 집합의 표현

백준 파이썬 1717번 집합의 표현Gold 5 https://www.acmicpc.net/problem/1717 집합에 대한 문제다. 유니온 파인드를 활용해 풀어주면 된다.더보기5 50 1 20 2 30 4 50 1 51 1 4막히면 위의 예시의 결과가 YES 가 나오는지 확인해보면 된다.import sysinput = sys.stdin.readlinesys.setrecursionlimit(10**9)def find_parent(x): if r[x] != x: r[x] = find_parent(r[x]) return r[x]def dfs(x, y): x = find_parent(x) y = find_parent(y) if x

IT/알고리즘 2025.02.21

[백준 Python] 1958번 LCS 3

백준 파이썬 1958번 LCS 3Gold 4 https://www.acmicpc.net/problem/1958 3개의 문자열을 비교하는 LCS 문제다 !처음에 a와 b를 비교하고, 그 비교값을 c와 비교하는 LCS 계산을 두 번 하는 방법으로 접근해서 푸는데 생각보다 오래 걸렸다.위와 같은 방식으로 접근을 하면 첫 계산에서 무조건 긴 문자열만 고르기 때문에 정답이 나올 수 없다.abcd abdc c기댓값 => 1, 결괏값 => 0그렇기 때문에 3차원 리스트를 생성해서 값을 비교해주어야 한다.a = input()b = input()c = input()dp = [[[0]*(len(c)+1) for _ in range(len(b)+1)] for _ in range(len(a)+1)]for i in range(..

IT/알고리즘 2025.02.17

[백준 Python] 14503번 로봇 청소기

백준 파이썬 14503번 로봇 청소기Gold 5 https://www.acmicpc.net/problem/14503문제가 길어서 어려워보이지만 간단한 구현 문제이다.import sysinput = sys.stdin.readlinefoward = [(-1, 0), (0, 1), (1, 0), (0, -1)]back = [(1, 0), (0, -1), (-1, 0), (0, 1)]def func(): global direction direction -= 1 if direction == -1: direction = 3 tx, ty = foward[direction] dx = tx+x dy = ty+y if lst[dx][dy] == 0 and not clean..

IT/알고리즘 2025.02.13

[백준 Python] 14728번 벼락치기

백준 파이썬 14728번 벼락치기Gold 5 https://www.acmicpc.net/problem/14728n, t = map(int, input().split())lst = [list(map(int, input().split())) for _ in range(n)] #공부시간, 배점dp = [0]*(t+1)for time, score in lst: for i in range(t, time-1, -1): dp[i] = max(dp[i], dp[i-time]+score)print(dp[t]) 냅색 유형의 문제로 dp를 사용해서 얻을 수 있는 최대점수를 구해주면 된다.다음 문제와 거의 똑같다!https://www.acmicpc.net/problem/12865

IT/알고리즘 2025.02.11