baekjoon 20260414

This commit is contained in:
songyc macbook 2026-04-14 22:27:13 +09:00
parent 8d2e900352
commit 7a2f8750f6
2 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,25 @@
#include <stdio.h>
int N;
void blank(int n) {
for(int i=0; i<n; i++)
printf(" ");
}
void star(int n) {
for(int i=0; i<n; i++)
printf("*");
}
int main() {
scanf("%d",&N);
for(int i=1; i<=N; i++) {
blank(N-i);
star(2*i - 1);
printf("\n");
}
return 0;
}

View File

@ -0,0 +1,44 @@
import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
candys = [0] + list(map(int, input().split()))
counts = [1] * (N+1)
parents = [i for i in range(N+1)]
def find(x) :
if parents[x] != x :
parents[x] = find(parents[x])
return parents[x]
def union(x, y) :
x = find(x)
y = find(y)
if x == y :
return
if x > 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])