diff --git a/code_study/Baekjoon/python/2098.py b/code_study/Baekjoon/python/2098.py new file mode 100644 index 0000000..af2112d --- /dev/null +++ b/code_study/Baekjoon/python/2098.py @@ -0,0 +1,29 @@ +import sys +input = sys.stdin.readline +Inf = sys.maxsize + +N = int(input()) +W = [list(map(int, input().split())) for _ in range(N)] + +dp = [[None] * (2**N) for _ in range(N)] + +def trevel(now, visited) : + if visited == ((1 << N) - 1) : + return w if (w := W[now][0]) != 0 else Inf + + if dp[now][visited] is not None : + return dp[now][visited] + + min_cost = Inf + for nxt in range(N) : + if W[now][nxt] == 0 or (visited & (1 << nxt)) != 0 : + continue + + cost = W[now][nxt] + trevel(nxt, visited | (1 << nxt)) + min_cost = min(min_cost, cost) + + dp[now][visited] = min_cost + + return dp[now][visited] + +print(trevel(0, 1)) \ No newline at end of file diff --git a/code_study/Baekjoon/python/6749.py b/code_study/Baekjoon/python/6749.py new file mode 100644 index 0000000..9ba6a07 --- /dev/null +++ b/code_study/Baekjoon/python/6749.py @@ -0,0 +1 @@ +print((lambda x, y : y + (y-x))(int(input()), int(input()))) \ No newline at end of file diff --git a/code_study/Baekjoon/python/9328.py b/code_study/Baekjoon/python/9328.py new file mode 100644 index 0000000..8173c92 --- /dev/null +++ b/code_study/Baekjoon/python/9328.py @@ -0,0 +1,64 @@ +from collections import deque +import sys +input = sys.stdin.readline + +ans = [] + +def solv() : + h, w = map(int, input().split()) + + Map = [] + Map.append("." * (w + 2)) + for _ in range(h) : + Map.append("." + input().rstrip() + ".") + Map.append("." * (w + 2)) + + key = [False] * 26 + for k in input().rstrip() : + if k != "0" : + key[ord(k) - ord("a")] = True + + qu = deque() + gate = [deque() for _ in range(26)] + qu.append((0,0)) + visited = [[False] * (w + 2) for _ in range(h + 2)] + res = 0 + + while qu : + cx, cy = qu.popleft() + + for dx, dy in zip([1,-1,0,0], [0,0,1,-1]) : + nx, ny = cx + dx, cy + dy + + if nx < 0 or nx >= w+2 or ny < 0 or ny >= h+2 or visited[ny][nx] or Map[ny][nx] == "*" : + continue + + ch = Map[ny][nx] + + if ord("A") <= ord(ch) <= ord("Z") : + if not key[ord(ch) - ord("A")] : + gate[ord(ch) - ord("A")].append((nx, ny)) + else : + qu.append((nx, ny)) + + elif ord("a") <= ord(ch) <= ord("z") : + qu.append((nx, ny)) + key[ord(ch) - ord("a")] = True + while gate[ord(ch) - ord("a")] : + qu.append(gate[ord(ch) - ord("a")].popleft()) + + elif ch == "$" : + res += 1 + qu.append((nx, ny)) + + else : + qu.append((nx, ny)) + + visited[ny][nx] = True + + ans.append(res) + +for _ in range(int(input())) : + solv() + +print("\n".join(map(str, ans))) \ No newline at end of file