diff --git a/SeongHoonC/README.md b/SeongHoonC/README.md index 7edeb92..bfe3752 100644 --- a/SeongHoonC/README.md +++ b/SeongHoonC/README.md @@ -8,16 +8,19 @@ | 4차시 | 2024.01.24 | 구현 | 마법의 엘리베이터 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/11 | | 5차시 | 2024.01.27 | 그리디 | 광물 캐기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/13 | | 6차시 | 2024.02.05 | 큐/스택 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/20 | -| 7차시 | 2024.02.08 | DP | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/23 | -| 8차시 | 2024.02.14 | 정렬 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/26 | -| 9차시 | 2024.02.21 | bfs | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/35 | -| 10차시 | 2024.02.23 | 그리디 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/38 | -| 11차시 | 2024.02.26 | 재귀 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/40 | -| 12차시 | 2024.02.29 | 분할정복 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/45 | -| 13차시 | 2024.03.03 | bfs | |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/49 | -| 14차시 | 2024.03.06 | dfs | |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/50 | -| 15차시 | 2024.03.09 | 분할정복 | |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/55 | -| 16차시 | 2024.03.14 | 누적합 | |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/60 | -| 17차시 | 2024.03.17 | 특정한 최단 경로 | |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/62 | -| 18차시 | 2024.03.28 | 구현 | |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/70 | +| 7차시 | 2024.02.08 | DP | 정수 삼각형 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/23 | +| 8차시 | 2024.02.14 | 정렬 | 좌표 압축 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/26 | +| 9차시 | 2024.02.21 | bfs | 헌내기는 친구가 필요해 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/35 | +| 10차시 | 2024.02.23 | 그리디 | 회의실 배정 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/38 | +| 11차시 | 2024.02.26 | 재귀 | Z | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/40 | +| 12차시 | 2024.02.29 | 분할정복 | 색종이 만들기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/45 | +| 13차시 | 2024.03.03 | bfs | 쉬운 최단거리 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/49 | +| 14차시 | 2024.03.06 | dfs | 불량 사용자 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/50 | +| 15차시 | 2024.03.09 | 분할정복 | 곱셈 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/55 | +| 16차시 | 2024.03.14 | 누적합 | 구간 합 구하기 4 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/60 | +| 17차시 | 2024.03.17 | 다익스트라 | 특정한 최단 경로 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/62 | +| 18차시 | 2024.03.28 | 구현 | 인구이동 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/70 | +| 19차시 | 2024.04.04 | 그리디 | 큰 수 만들기 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/72 | +| 20차시 | 2024.04.07 | DP | |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/75 | +| 21차시 | 2024.04.11 | DP | RGB거리 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/77 | --- diff --git "a/SeongHoonC/dp/RGB\352\261\260\353\246\254.kt" "b/SeongHoonC/dp/RGB\352\261\260\353\246\254.kt" new file mode 100644 index 0000000..674543f --- /dev/null +++ "b/SeongHoonC/dp/RGB\352\261\260\353\246\254.kt" @@ -0,0 +1,27 @@ +import java.io.BufferedReader +import java.io.InputStreamReader + +const val MAX = 987_654_321 +val colors = 1..3 +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + val n = br.readLine().toInt() + val graph = Array(4) { Array(n + 1) { 0 } } + val dp = Array(4) { Array(n + 1) { 0 } } + for (i in 0 until n) { + val line = br.readLine().split(" ").map { it.toInt() } + for (j in 0..2) { + graph[j + 1][i + 1] = line[j] + } + } + + // 각 집마다 현재 이 색을 칠할 때 최소값을 구한다 + for (houseIndex in 1..n) { + for (colorIndex in colors) { + dp[colorIndex][houseIndex] = colors.minOf { + if (it == colorIndex) MAX else dp[it][houseIndex - 1] + graph[colorIndex][houseIndex] + } + } + } + println(colors.minOf { dp[it][n] }) +} diff --git "a/SeongHoonC/dp/\354\225\261.kt" "b/SeongHoonC/dp/\354\225\261.kt" new file mode 100644 index 0000000..6ba6df5 --- /dev/null +++ "b/SeongHoonC/dp/\354\225\261.kt" @@ -0,0 +1,34 @@ +import java.io.BufferedReader +import java.io.InputStreamReader +import kotlin.math.max +import kotlin.math.min + +const val MAX_COST = 10_000 +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + val (n, m) = br.readLine().split(" ").map { it.toInt() } + + // 비용의 최대는 100 * 100 이다 + val dp = Array(n + 1) { Array(MAX_COST + 1) { 0 } } + val bytes = listOf(0) + br.readLine().split(" ").map { it.toInt() } + val cost = listOf(0) + br.readLine().split(" ").map { it.toInt() } + + var minCost = Int.MAX_VALUE + for (i in 1..n) { + for (j in 0..MAX_COST) { + // 담을 수 없다면 이전에 i-1 까지 담아놓은 것 그대로 + if (j - cost[i] < 0) { + dp[i][j] = dp[i - 1][j] + continue + } + // 담을 수 있다면 현재 비용 - 앱의 비용 최적값에 얻을 수 있는 용량 더하기 + dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - cost[i]] + bytes[i]) + + // 목표 용량을 넘었다면 정답 최소값 업데이트 + if (dp[i][j] >= m) { + minCost = min(minCost, j) + } + } + } + println(minCost) +} diff --git "a/SeongHoonC/greedy/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260_\353\260\261\354\244\200.kt" "b/SeongHoonC/greedy/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260_\353\260\261\354\244\200.kt" new file mode 100644 index 0000000..5bb1d22 --- /dev/null +++ "b/SeongHoonC/greedy/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260_\353\260\261\354\244\200.kt" @@ -0,0 +1,28 @@ +import java.io.BufferedReader +import java.io.InputStreamReader +import java.util.PriorityQueue + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + val n = br.readLine().toInt() + val numbers = br.readLine().split(" ") + val queue = PriorityQueue() + numbers.forEach { + queue.add(Target(it)) + } + val stringBuilder = StringBuilder() + while (queue.isNotEmpty()) { + stringBuilder.append(queue.poll().number) + } + if (stringBuilder.all { it == '0' }) { + println(0) + return + } + println(stringBuilder.toString()) +} + +data class Target(val number: String) : Comparable { + override fun compareTo(other: Target): Int { + return if (number + other.number > other.number + number) -1 else 1 + } +} diff --git "a/alstjr7437/BFS/\354\210\250\353\260\224\352\274\255\354\247\210.py" "b/alstjr7437/BFS/\354\210\250\353\260\224\352\274\255\354\247\210.py" new file mode 100644 index 0000000..706325e --- /dev/null +++ "b/alstjr7437/BFS/\354\210\250\353\260\224\352\274\255\354\247\210.py" @@ -0,0 +1,28 @@ +from collections import deque + +n, k = map(int, input().split()) + +result = [0] * 100001 +result[n] = 1 + +queue = deque() +queue.append(n) + +while queue: + now = queue.popleft() + if now == k: + break + # -1 로직 + if now - 1 >= 0 and result[now-1] == 0 : + queue.append(now-1) + result[now-1] = result[now] + 1 + # +1 로직 + if now + 1 < len(result) and result[now+1] == 0: + queue.append(now+1) + result[now+1] = result[now] + 1 + # *2 로직 + if now * 2 < len(result) and result[now * 2] == 0: + queue.append(now*2) + result[now*2] = result[now] + 1 + +print(result[k] - 1) \ No newline at end of file diff --git "a/alstjr7437/DP/\352\265\254\352\260\204-\353\202\230\353\210\204\352\270\260.py" "b/alstjr7437/DP/\352\265\254\352\260\204-\353\202\230\353\210\204\352\270\260.py" new file mode 100644 index 0000000..6c56569 --- /dev/null +++ "b/alstjr7437/DP/\352\265\254\352\260\204-\353\202\230\353\210\204\352\270\260.py" @@ -0,0 +1,21 @@ +# n, m = map(int,input()) + +# num = [ i for i in range(n): int(input())] + +# dp = [[-1e9] * m for _ in range(n+1)] +# for i in range(n): + +import sys +input = sys.stdin.readline + +n, m = map(int, input().split()) +dp1 = [[0]+[-1e9]*m for i in range(n+1)] +dp2 = [[0]+[-1e9]*m for i in range(n+1)] +num = [int(input()) for i in range(n) ] + +for i in range(1, n+1): + for j in range(1, min(m, (i+1)//2)+1): + dp2[i][j]=max(dp1[i-1][j], dp2[i-1][j]) + dp1[i][j]=max(dp1[i-1][j], dp2[i-1][j-1])+num[i-1] +print(max(dp1[n][m], dp2[n][m])) + diff --git a/alstjr7437/README.md b/alstjr7437/README.md index 4b3dfca..edb08f4 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -17,4 +17,8 @@ | 13차시 | 2024.02.29 | DP | 쉬운 계단 수 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/42 | | 14차시 | 2024.03.03 | 브루트포스 | 마인크래프트 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/48 | | 15차시 | 2024.03.09 | 우선순위 큐 | 파일 합치기3 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/53 | -| 16차시 | 2024.03.13 | 정렬 | 선 긋기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/57 | \ No newline at end of file +| 16차시 | 2024.03.13 | 정렬 | 선 긋기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/57 | +| 17차시 | 2024.03.16 | DP | 구간 나누기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/61 | +| 18차시 | 2024.03.23 | 다익스트라 | 최단 경로 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/66 | +| 19차시 | 2024.03.27 | 문자열 | IOIOI | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/67 | +| 20차시 | 2024.04.03 | BFS | 숨바꼭질 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/70 | \ No newline at end of file diff --git "a/alstjr7437/\352\265\254\355\230\204/IOIOI.swift" "b/alstjr7437/\352\265\254\355\230\204/IOIOI.swift" new file mode 100644 index 0000000..1dc2822 --- /dev/null +++ "b/alstjr7437/\352\265\254\355\230\204/IOIOI.swift" @@ -0,0 +1,41 @@ +let n = Int(readLine()!)! +let m = Int(readLine()!)! + +let s = readLine()!.map{$0} + +var result = 0 +var cur = 0 +var count = 0 + +while cur < m-2{ + if String(s[cur...cur + 2]) == "IOI"{ + count += 1 + cur += 2 + if count == n{ + result += 1 + count -= 1 + } + } else { + count = 0 + cur += 1 + } +} + +print(result) + + +""" +50점짜리 코드 + +var p = "I" +for _ in 0 ..< n{ + p += "OI" +} + +for i in 0..= len(bomb): + temp = [] + for j in range(len(bomb)): + temp.append(stack.pop()) + if temp == bomb: + continue + else: + for j in range(len(temp), 0, -1): + stack.append(temp[j-1]) + +if len(stack) == 0: + print('FRULA') +else: + for i in range(len(stack)): + print(stack[i], end='') diff --git a/wkdghdwns199/ACM-26069.py b/wkdghdwns199/ACM-26069.py new file mode 100644 index 0000000..c24cfe0 --- /dev/null +++ b/wkdghdwns199/ACM-26069.py @@ -0,0 +1,25 @@ +import sys +input = sys.stdin.readline +N = int(input()) +dancingCheck = {} +dancingCheck['ChongChong'] = True +for _ in range(N): + left_rabbit, right_rabbit = map(str, input().split()) + try : + if dancingCheck[left_rabbit]: + dancingCheck[right_rabbit] = True + except : + dancingCheck[left_rabbit] = False + + try : + if dancingCheck[right_rabbit] : + dancingCheck[left_rabbit] = True + except : + dancingCheck[right_rabbit] = False + +count=0 +for key in dancingCheck.keys(): + if dancingCheck[key] == True: + count+=1 + +print(count) \ No newline at end of file diff --git a/wkdghdwns199/README.md b/wkdghdwns199/README.md index c033c6d..b9791e3 100644 --- a/wkdghdwns199/README.md +++ b/wkdghdwns199/README.md @@ -18,5 +18,7 @@ | 14차시 | 2024.03.13 | 집합과 맵 | 영단어 암기는 괴로워 | 2024.03.13 | | 15차시 | 2024.03.20 | 우선순위 큐 | 절댓값 힙 | 2024.03.20 | | 16차시 | 2024.03.23 | 조합론 | 이항 계수 1 | 2024.03.23 | +| 17차시 | 2024.03.27 | DP | 신나는 함수 실행 | 2024.03.27 | +| 18차시 | 2024.04.03 | 집합과 맵 | 절댓값 힙 | 2024.04.03 | | 19차시 | 2024.04.07 | 조합론 | 인사성 밝은 곰곰이 | 2024.04.07 | diff --git "a/wkdghdwns199/\353\217\231\354\240\201_\352\263\204\355\232\215\353\262\225_1/ACM-24416.py" "b/wkdghdwns199/\353\217\231\354\240\201_\352\263\204\355\232\215\353\262\225_1/ACM-24416.py" new file mode 100644 index 0000000..aa59f54 --- /dev/null +++ "b/wkdghdwns199/\353\217\231\354\240\201_\352\263\204\355\232\215\353\262\225_1/ACM-24416.py" @@ -0,0 +1,25 @@ +import sys +input = sys.stdin.readline + +def fib(n) : + global countFib + if n==1 or n==2: + countFib += 1 + return 1 + else : + return fib(n-1) + fib(n-2) + +def fibo(n): + global countFibo + f = [0 for _ in range(n+1)] + f[1] = f[2] = 1 + for idx in range(3, n+1): + countFibo+=1 + f[idx] = f[idx-1] + f[idx-2] + return f[n] + +N = int(input()) +countFib = countFibo = 0 +fib(N) +fibo(N) +print(countFib, countFibo) \ No newline at end of file diff --git "a/wkdghdwns199/\353\217\231\354\240\201_\352\263\204\355\232\215\353\262\225_1/ACM-9184.py" "b/wkdghdwns199/\353\217\231\354\240\201_\352\263\204\355\232\215\353\262\225_1/ACM-9184.py" new file mode 100644 index 0000000..c421a18 --- /dev/null +++ "b/wkdghdwns199/\353\217\231\354\240\201_\352\263\204\355\232\215\353\262\225_1/ACM-9184.py" @@ -0,0 +1,25 @@ +import sys +input = sys.stdin.readline + +def w(a,b,c): + if a<=0 or b<=0 or c<=0 : + return 1 + if a>20 or b>20 or c>20: + return w(20,20,20) + if dp[a][b][c] : + return dp[a][b][c] + if a= N or nb>= N or nb<0 or na <0 or visited[na][nb]==1: + continue + if R>=abs(country[a][b]-country[na][nb]) >= L: + visited[na][nb] = 1 + q.append((na,nb)) + union.append((na,nb)) + if len(union)<=1: + return 0 + result=sum(country[a][b] for a,b in union) // len(union) + for a,b in union: + country[a][b] = result + + return 1 +day=0 + +while True : + stop = 0 + visited = [[0]*N for _ in range(N)] + for i in range(N): + for j in range(N): + if visited[i][j] == 0: + visited[i][j] = 1 + stop += bfs(i,j) + if stop ==0: + break + day+=1 +print(day) \ No newline at end of file