baekjoon 20260414
This commit is contained in:
parent
8d2e900352
commit
7a2f8750f6
25
code_study/Baekjoon/c/2442.c
Normal file
25
code_study/Baekjoon/c/2442.c
Normal 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;
|
||||||
|
}
|
||||||
44
code_study/Baekjoon/python/20303.py
Normal file
44
code_study/Baekjoon/python/20303.py
Normal 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])
|
||||||
Loading…
x
Reference in New Issue
Block a user