diff --git a/code_study/Baekjoon/c/2442.c b/code_study/Baekjoon/c/2442.c new file mode 100644 index 0000000..e5955bc --- /dev/null +++ b/code_study/Baekjoon/c/2442.c @@ -0,0 +1,25 @@ +#include + +int N; + +void blank(int n) { + for(int i=0; i y : + x, y = y, x + + parents[y] = x + candys[x] += candys[y] + counts[x] += counts[y] + +for _ in range(M) : + u, v = map(int, input().split()) + union(u, v) + +items = [] +for i in range(1, N+1) : + if i == parents[i] : + items.append((counts[i], candys[i])) + +dp = [0] * K + +for weight, value in items : + for w in range(K-1, weight-1, -1) : + dp[w] = max(dp[w], dp[w-weight] + value) + +print(dp[K-1]) \ No newline at end of file