diff --git "a/Seol-Munhyeok/.cph/.\353\246\254\353\252\250\354\273\250.py_a16f81a5bbad4f26e190f44fb779d889.prob" "b/Seol-Munhyeok/.cph/.\353\246\254\353\252\250\354\273\250.py_a16f81a5bbad4f26e190f44fb779d889.prob" new file mode 100644 index 0000000..f5beff5 --- /dev/null +++ "b/Seol-Munhyeok/.cph/.\353\246\254\353\252\250\354\273\250.py_a16f81a5bbad4f26e190f44fb779d889.prob" @@ -0,0 +1 @@ +{"name":"Local: 리모컨","url":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\리모컨.py","tests":[{"id":1754987353256,"input":"14124\n0","output":"5"},{"id":1754988380935,"input":"5457\n3\n6 7 8","output":"6"},{"id":1754988677269,"input":"100\n5\n0 1 2 3 4","output":"0"},{"id":1754988684813,"input":"500000\n8\n0 2 3 4 6 7 8 9","output":"11117"},{"id":1754988691940,"input":"100\n3\n1 0 5","output":"0"},{"id":1754988697420,"input":"14124\n0","output":"5"},{"id":1754988702699,"input":"1\n9\n1 2 3 4 5 6 7 8 9","output":"2"},{"id":1754988714138,"input":"80000\n2\n8 9","output":"2228"},{"id":1754988820882,"input":"889\n9\n0 2 3 4 5 6 7 8 9","output":"226"},{"id":1754989157813,"input":"444445\n8\n0 2 3 4 5 7 8 9","output":"166672"},{"id":1754989169307,"input":"500000\n8\n0 1 2 4 6 7 8 9","output":"33339"},{"id":1754989180067,"input":"99\n2\n8 9","output":"1"},{"id":1754989184555,"input":"102\n2\n0 2","output":"2"},{"id":1754989195898,"input":"9999\n0","output":"4"},{"id":1754989201025,"input":"0\n1\n0","output":"2"},{"id":1754989315623,"input":"1000\n1\n1","output":"4"},{"id":1754989417270,"input":"1\n3\n1 2 3","output":"2"},{"id":1754989429332,"input":"9\n2\n8 9","output":"3"},{"id":1754989435271,"input":"0\n0","output":"1"},{"id":1754989491519,"input":"1000\n1\n1","output":"4"},{"id":1754989501294,"input":"123456\n6\n1 2 3 4 5 6","output":"23462"},{"id":1754989509455,"input":"59\n2\n5 9","output":"3"},{"id":1754989519933,"input":"5678\n7\n2 3 4 5 6 7 8","output":"3326"},{"id":1754989526126,"input":"1987\n3\n7 8 9","output":"17"},{"id":1754989540812,"input":"44\n6\n4 5 6 7 8 9","output":"13"},{"id":1754989549595,"input":"999\n1\n9","output":"5"},{"id":1754989558427,"input":"189898\n6\n3 5 6 7 8 9","output":"10108"},{"id":1754989585649,"input":"1000\n2\n0 1","output":"4"},{"id":1754989596879,"input":"5\n9\n1 2 3 4 5 6 7 8 9","output":"6"},{"id":1754989606046,"input":"11\n9\n1 2 3 4 5 6 7 8 9","output":"12"},{"id":1754989613405,"input":"833\n4\n3 7 8 9","output":"170"},{"id":1754989621981,"input":"9\n1\n9","output":"2"},{"id":1754989674336,"input":"1555\n3\n0 1 9","output":"670"},{"id":1754989684408,"input":"99933\n2\n3 9","output":"73"},{"id":1754989814035,"input":"1\n9\n0 1 2 3 4 5 6 7 8","output":"9"},{"id":1754989833658,"input":"500000\n9\n1 2 3 4 5 6 7 8 9","output":"499900"},{"id":1754990071949,"input":"99\n0","output":"1"},{"id":1754990079541,"input":"101\n0","output":"1"},{"id":1754990158734,"input":"104\n1\n4","output":"4"},{"id":1754990209041,"input":"500000\n1\n0","output":"7"},{"id":1754990336183,"input":"1\n9\n0 1 2 3 4 5 6 7 8","output":"9"},{"id":1754990398465,"input":"140200\n3\n4 5 6","output":"207"},{"id":1754990636701,"input":"103\n5\n2 3 5 7 8","output":"3"},{"id":1754990644548,"input":"217\n7\n0 1 2 4 5 7 8","output":"117"},{"id":1754990660362,"input":"500000\n0","output":"6"},{"id":1754990707982,"input":"1022\n5\n1 2 3 4 5 ","output":"26"},{"id":1754990718062,"input":"499998\n3\n4 8 9 ","output":"8"},{"id":1754990727461,"input":"1698\n2\n6 9","output":"6"},{"id":1754990733796,"input":"30002\n3\n1 3 4","output":"8"},{"id":1754990775185,"input":"991\n1\n1","output":"4"},{"id":1754990785327,"input":"30002\n3\n1 3 4","output":"8"},{"id":1754990794984,"input":"101\n9\n0 1 2 3 4 5 6 7 8 ","output":"1"},{"id":1754990802671,"input":"394344\n3\n1 2 3","output":"5662"},{"id":1754990826429,"input":"100\n10\n0 1 2 3 4 5 6 7 8 9 \n0","output":"0"},{"id":1754990861826,"input":"1\n9\n0 1 2 3 4 5 6 7 8 ","output":"9"},{"id":1754990938890,"input":"123\n3\n1 2 5","output":"23"},{"id":1754990946378,"input":"190000\n3\n1 2 9","output":"101117"},{"id":1754990953482,"input":"10\n1\n1","output":"2"},{"id":1754990961393,"input":"9999\n8\n0 1 2 3 4 5 6 7","output":"4"},{"id":1754990972344,"input":"5959\n4\n1 2 3 4","output":"4"},{"id":1754990984622,"input":"19\n1\n1","output":"3"},{"id":1754990998486,"input":"0\n10\n0 1 2 3 4 5 6 7 8 9","output":"100"},{"id":1754991058402,"input":"500000\n10\n0 1 2 3 4 5 6 7 8 9","output":"499900"},{"id":1754991074615,"input":"6 \n9\n0 2 3 4 5 6 7 8 9","output":"6"},{"id":1754991088278,"input":"10 \n9 \n1 2 3 4 5 6 7 8 9","output":"11"},{"id":1754991094733,"input":"101\n0","output":"1"},{"id":1754991103932,"input":"0\n0","output":"1"},{"id":1754991563596,"input":"9\n8\n9 8 7 6 5 4 3 2","output":"3"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\리모컨.py","group":"local","local":true} \ No newline at end of file diff --git a/Seol-Munhyeok/README.md b/Seol-Munhyeok/README.md index 9095310..5f4f0a5 100644 --- a/Seol-Munhyeok/README.md +++ b/Seol-Munhyeok/README.md @@ -12,4 +12,5 @@ | 16차시 | 2025.07.30 | 트리, 분할 정복, 재귀 | [트리의 순회](https://www.acmicpc.net/problem/2263) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/58 | | 17차시 | 2025.08.01 | 구현, 시뮬레이션, 백트래킹 | [청소년 상어](https://www.acmicpc.net/problem/19236) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/61 | | 18차시 | 2025.08.05 | 브루트포스, 애드 혹, 홀짝성 | [램프](https://www.acmicpc.net/problem/1034) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/62 | -| 19차시 | 2025.08.10 | 구현, BFS | [거리두기 확인하기](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/67 | \ No newline at end of file +| 19차시 | 2025.08.10 | 구현, BFS | [거리두기 확인하기](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/67 | +| 20차시 | 2025.08.14 | DP | [코딩 테스트 공부](https://school.programmers.co.kr/learn/courses/30/lessons/118668) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/73 | \ No newline at end of file diff --git "a/Seol-Munhyeok/\353\246\254\353\252\250\354\273\250.py" "b/Seol-Munhyeok/\353\246\254\353\252\250\354\273\250.py" new file mode 100644 index 0000000..34df960 --- /dev/null +++ "b/Seol-Munhyeok/\353\246\254\353\252\250\354\273\250.py" @@ -0,0 +1,48 @@ +n = int(input()) +m = int(input()) +lst = list(map(int, input().split())) if m > 0 else [] +cand = [i for i in range(10) if i not in lst] # 사용 가능한 숫자 버튼 +length = len(str(n)) + +answer = int(1e9) + +def brute(arr, r, depth, value): + global n, answer + if depth == r: + answer = min(answer, r + abs(n - value)) + return + for num in arr: + brute(arr, r, depth + 1, value * 10 + num) + +def solve(num): + global answer + # 기본값: 숫자 버튼 안 쓰고 +/- + answer = abs(num - 100) + + # [1] 채널이 100인 경우 + if num == 100: + return 0 + + # [2] 100 근처 채널 예외 처리 + if num == 101 or num == 99: + return 1 + if num == 102 or num == 98: + return 2 + if num == 103: + return 3 + + # [3] 모두 고장 + if m == 10: + return answer + + # [4] 아무것도 안 고장 + if m == 0: + return len(str(num)) + + # [5] 모든 자릿수마다 경우의 수 체크 + for r in range(1, length + 2): + brute(cand, r, 0, 0) + + return answer + +print(solve(n)) \ No newline at end of file diff --git "a/Seol-Munhyeok/\354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270 \352\263\265\353\266\200.py" "b/Seol-Munhyeok/\354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270 \352\263\265\353\266\200.py" new file mode 100644 index 0000000..3ef4c0b --- /dev/null +++ "b/Seol-Munhyeok/\354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270 \352\263\265\353\266\200.py" @@ -0,0 +1,27 @@ +def solution(alp, cop, problems): + INF = int(1e9) + maxA = max(p[0] for p in problems) + maxC = max(p[1] for p in problems) + + # 초기의 알고력(코딩력) 자체가 alp_max(cop_max)보다 높은 경우에 대한 예외처리 + alp, cop = min(alp, maxA), min(cop, maxC) + + # dp[a][c] : 알고력 a, 코딩력 c를 얻는데 걸린 시간 + dp = [[INF for _ in range(maxC + 1)] for _ in range(maxA + 1)] + dp[alp][cop] = 0 # 초기값 설정 + + # DP + for a in range(alp, maxA + 1): + for c in range(cop, maxC + 1): + # 공부하는 경우 + ta, tc = min(maxA, a+1), min(maxC, c+1) + dp[ta][c] = min(dp[ta][c], dp[a][c] + 1) + dp[a][tc] = min(dp[a][tc], dp[a][c] + 1) + + # 문제 풀이하는 경우 + for alp_req, cop_req, alp_rwd, cop_rwd, cost in problems: + if a >= alp_req and c >= cop_req: + na, nc = min(maxA, a + alp_rwd), min(maxC, c + cop_rwd) + dp[na][nc] = min(dp[na][nc], dp[a][c] + cost) + + return dp[maxA][maxC] \ No newline at end of file