diff --git "a/src/main/kotlin/byeonghee/week59/\353\217\231\354\240\204.kt" "b/src/main/kotlin/byeonghee/week59/\353\217\231\354\240\204.kt" new file mode 100644 index 00000000..48672f52 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week59/\353\217\231\354\240\204.kt" @@ -0,0 +1,34 @@ +package byeonghee.week59 + +class 소병희_동전 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val t = readLine().toInt() + repeat(t) { + val n = readLine().toInt() + val coins = IntArray(n) + + readLine().split(" ").forEachIndexed { i, v -> coins[i] = v.toInt() } + + val price = readLine().toInt() + val dp = Array(price + 1) { IntArray(n) } + + repeat(n) { i -> if (price >= coins[i]) dp[coins[i]][i] = 1 } + for(p in 1 .. price) { + for((i, c) in coins.withIndex()) { + if (p < c) continue + for(pre in 0 .. i) { + dp[p][i] += dp[p - c][pre] + } + } + } + + println(dp[price].sumOf { it }) + } + } + } +} + +fun main() { + 소병희_동전.solve() +} diff --git "a/src/main/kotlin/byeonghee/week59/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" "b/src/main/kotlin/byeonghee/week59/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" new file mode 100644 index 00000000..36b57997 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week59/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" @@ -0,0 +1,23 @@ +package byeonghee.week59 + +class 소병희_멀쩡한사각형 { + fun solution(w: Int, h: Int): Long { + val gcd = gcd(w, h) + val sw = w / gcd + val sh = h / gcd + val adj = 1 + (sw - 1) + (sh - 1) + + return (0L + w) * h - gcd * adj + } +} + +fun gcd(_a: Int, _b: Int): Int { + var a = _a + var b = _b + + while(b > 0) { + a = b.also { b = a % b } + } + + return a +} \ No newline at end of file diff --git "a/src/main/kotlin/byeonghee/week59/\355\203\235\353\260\260 \353\260\260\354\206\241.kt" "b/src/main/kotlin/byeonghee/week59/\355\203\235\353\260\260 \353\260\260\354\206\241.kt" new file mode 100644 index 00000000..ccb72f99 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week59/\355\203\235\353\260\260 \353\260\260\354\206\241.kt" @@ -0,0 +1,48 @@ +package byeonghee.week59 + +import java.util.* + +class 소병희_택배배송 { + companion object { + data class Node(val i: Int, val v: Int) + + fun solve() = with(System.`in`.bufferedReader()) { + val (n, m) = readLine().split(" ").map { it.toInt() } + val dist = IntArray(n) { m * 1000 } + val edges = Array(n) { ArrayList() } + val pq = PriorityQueue(m + 2) { a, b -> (a.v- b.v) } + + var a = 0 + var b = 0 + var c = 0 + repeat(m) { + readLine().split(" ").let { + a = it[0].toInt() - 1 + b = it[1].toInt() - 1 + c = it[2].toInt() + edges[a].add(Node(b, c)) + edges[b].add(Node(a, c)) + } + } + + pq.add(Node(0, 0)) + while(pq.isNotEmpty()) { + val (i, v) = pq.poll() + if (dist[i] <= v) continue + + dist[i] = v + edges[i].forEach { x -> + if (dist[x.i] > v + x.v) + pq.add(Node(x.i, x.v + v)) + } + } + + println(dist[n-1]) + } + + } +} + +fun main() { + 소병희_택배배송.solve() +} \ No newline at end of file diff --git "a/src/main/kotlin/byeonghee/week59/\355\230\270\355\205\224.kt" "b/src/main/kotlin/byeonghee/week59/\355\230\270\355\205\224.kt" new file mode 100644 index 00000000..3ee89bbc --- /dev/null +++ "b/src/main/kotlin/byeonghee/week59/\355\230\270\355\205\224.kt" @@ -0,0 +1,37 @@ +package byeonghee.week59 + +class 소병희_호텔 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val (c, n) = readLine().split(" ").map { it.toInt() } + val cities = Array(n) { IntArray(2) } + val dp = IntArray(c * 100 + 1) + + repeat(n) { i -> + val (cost, people) = readLine().split(" ").map { it.toInt() } + cities[i][0] = cost + cities[i][1] = people + } + + for((cost, people) in cities) { + for(price in 1 .. c * 100) { + if (price - cost >= 0) { + dp[price] = dp[price] + .coerceAtLeast(dp[price - cost] + people) + } + } + } + + for(i in 1 .. c * 100) { + if (dp[i] >= c) { + println(i) + return@with + } + } + } + } +} + +fun main() { + 소병희_호텔.solve() +} \ No newline at end of file