Upload files to "백준"

This commit is contained in:
2026-04-11 11:57:13 +09:00
parent f9304411af
commit 5d9e621055
5 changed files with 117 additions and 0 deletions

15
백준/11722.py Normal file
View File

@@ -0,0 +1,15 @@
import sys
input = sys.stdin.readline
n = int(input())
lst = list(map(int, input().split()))
dp = [1 for _ in range(n)]
for i in range(n-1, -1 ,-1):
for j in range(n-1, i-1, -1):
if lst[i] > lst[j]:
dp[i] = max(dp[i], dp[j]+1)
print(max(dp))

30
백준/11724.py Normal file
View File

@@ -0,0 +1,30 @@
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
N, M = map(int, input().split())
A = list([] for i in range(N+1))
tot=0
visited = [0] * (N+1)
for _ in range(M):
s, e = map(int, input().split())
A[s].append(e)
A[e].append(s)
def DFS(v):
visited[v] = True
for i in A[v]:
if(visited[i]==False):
DFS(i)
for i in range(1,N+1):
if(visited[i]==False):
tot+=1
DFS(i)
print(tot)

18
백준/12015.py Normal file
View File

@@ -0,0 +1,18 @@
from bisect import bisect_left
import sys
input = sys.stdin.readline
n = int(input())
lst = list(map(int, input().split()))
stack = []
for i in lst:
if not stack or stack[-1] < i:
stack.append(i)
else:
a = bisect_left(stack, i)
stack[a] = i
print(len(stack))
print(*stack)

16
백준/13251.py Normal file
View File

@@ -0,0 +1,16 @@
from itertools import combinations
import sys
from math import factorial
from math import comb
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
k = int(input())
total = sum(a)
arrtot = 0
for i in a:
arrtot += comb(i, k)
print(arrtot / (comb(total, k)))

38
백준/14002.py Normal file
View File

@@ -0,0 +1,38 @@
import sys
from bisect import bisect_left
input = sys.stdin.readline
n = int(input())
lst = list(map(int, input().split()))
stack = []
stack_idx = []
dp_table = [1 for i in range(n+1)]
prev = [-1 for i in range(n+1)]
for i in range(n):
if not stack or stack[-1]<lst[i]:
stack.append(lst[i])
if stack_idx:
prev[i] = stack_idx[-1]
stack_idx.append(i)
else:
k = bisect_left(stack, lst[i])
stack[k] = lst[i]
if k > 0:
prev[i] = stack_idx[k-1]
stack_idx[k] = i
k = len(stack)
idx = stack_idx[-1]
result = []
while idx!=-1:
result.append(lst[idx])
idx = prev[idx]
result.reverse()
print(k)
print(*result)