diff --git a/week14/leGit-y/.gitkeep b/week14/leGit-y/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/week14/leGit-y/13549.py b/week14/leGit-y/13549.py new file mode 100644 index 0000000..1222e1d --- /dev/null +++ b/week14/leGit-y/13549.py @@ -0,0 +1,32 @@ +import heapq +import sys +input = sys.stdin.readline + +INF = int(1e9) + +N, K = map(int, input().split()) +distance = [INF] * 100001 + +def dijkstra(start): + distance[start] = 0 + q = [] + heapq.heappush(q, (0, start)) + + while q: + dist, now = heapq.heappop(q) + if distance[now] < dist: + continue + for n in (now+1, now-1, now*2): + if n < 0 or n > 100000: + continue + + cost = dist + if n != now*2: + cost = dist + 1 + + if cost < distance[n]: + distance[n] = cost + q.append((cost, n)) + +dijkstra(N) +print(distance[K]) \ No newline at end of file diff --git a/week14/leGit-y/1562.py b/week14/leGit-y/1562.py new file mode 100644 index 0000000..690d3db --- /dev/null +++ b/week14/leGit-y/1562.py @@ -0,0 +1,48 @@ +""" +10844. 쉬운 계단 수 문제와 유사 +다른 점은 0~9까지의 모든 수를 써야한다는 조건이 추가된 부분 +해당 부분을 체크하기 위한 bitmask 저장공간만 추가 +dp[글자길이][마지막수][방문집합(bitmask)] +""" +import sys +input = sys.stdin.readline + +MOD = 10**9 +N = int(input()) + +""" +dp[수의길이][마지막수][방문집합] +1) 방문집합: 0~9까지의 수들 중 어느것 포함되는지 체크 + 크기: 1<<10 +2) 마지막수: 가능한 수들 (0~9) + 크기: 10 +3) 수의길이: 입력값 (N) +""" +dp = [[[0 for _ in range(1<<10)] for _ in range(10)] for _ in range(N + 1)] + +# 0으로 시작하든 수는 계단수 x, 따라서 범위 1부터 시작 +for k in range(1, 10): + dp[1][k][1 << k] = 1 + +for i in range(2,N+1): + for j in range(10): + for k in range(1<<10): + bit = k | (1<