본문 바로가기

분류 전체보기263

[백준] 1339번 - 단어 수학 (파이썬) # 단어 수학 from collections import deque N = int(input()) arr = [] for _ in range(N): arr.append(deque(list(input().strip()))) alpha = {} for i in range(N): j = 0 while True: if len(arr[i]) == 0: break if arr[i][j] in alpha: alpha[arr[i].popleft()] += 10**(len(arr[i])) else: alpha[arr[i].popleft()] = 10**(len(arr[i])-1) list = [] for i in alpha.values(): list.append(i) list.sort(reverse=True) resul.. 2022. 1. 27.
[백준] 12015번 - 가장 긴 증가하는 부분 수열 2 (파이썬) # 가장 긴 증가하는 부분 수열 2 import sys import bisect input = sys.stdin.readline N = int(input()) arr = list(map(int, input().split())) result = [] result.append(arr[0]) for i in range(1, N): if arr[i] > result[-1]: result.append(arr[i]) else: index = bisect.bisect_left(result, arr[i]) result[index] = arr[i] print(len(result)) 이진탐색, bisect 1. 전체 리스트를 돌면서 - result의 마지막 원소보다 크면 append를 해준다 - 작으면 bisect_lef.. 2022. 1. 27.
[백준] 11053번 - 가장 긴 증가하는 부분 수열 (파이썬) # 가장 긴 증가하는 부분 수열 import sys N = int(input()) arr = list(map(int, sys.stdin.readline().split())) dp = [1] * N for i in range(1, N): for j in range(i): if arr[j] < arr[i]: dp[i] = max(dp[i], dp[j] + 1) print(max(dp)) DP, LIS알고리즘 1. 2중 for문을 이용해서 (j < i) - dp(현재까지의 가장 긴 증가하는 부분수열의 길이)를 업데이트 해나간다 - i 까지 이전의 dp를 이용해서 업데이트 해나가고 i를 하나씩 늘려가면서 다시 해나간다 2. dp의 값중 가장 큰 값을 출력 LIS(가장 긴 증가하는 부분 수열 알고리즘) 시간복잡도.. 2022. 1. 27.
[백준] 1967번 - 트리의 지름 (파이썬) # 트리의 지름 from collections import deque import sys input = sys.stdin.readline V = int(input()) arr = [[] for _ in range(V+1)] for _ in range(V): temp = list(map(int, input().split())) v = temp[0] for i in range(1, len(temp)-2, 2): arr[v].append((temp[i], temp[i+1])) far_node = 0 def find(a, c): global far_node q = deque() q.append((a, c)) visited = [False] * (V+1) visited[a] = True result = 0 whi.. 2022. 1. 27.
[백준] 14889번 - 스타트와 링크 (파이썬) # 스타트와 링크 import sys MAX = sys.maxsize N = int(input()) arr = [] for _ in range(N): arr.append(list(map(int, input().split()))) people = [i for i in range(N)] start_team = [] result = MAX def chooseMember(num, k): global result if num == N//2: link_team = [] link_team = list(set(people) - set(start_team)) result = min(result, abs(getScore(link_team) - getScore(start_team))) return for i in range.. 2022. 1. 27.
[백준] 14501번 - 퇴사 (파이썬) # 퇴사 N = int(input()) arr = [] for _ in range(N): day, pay = map(int, input().split()) arr.append((day, pay)) dp = [0] * (N+1) for i in range(N-1, -1, -1): day = arr[i][0] pay = arr[i][1] if day + i 2022. 1. 27.
[리액트(React)] 7. 리액트훅(Hook) - 심화편 memo, useMemo, useCallback에 대해서 공부해보자 1. memo - 컴포넌트 자체를 메모이제이션해서 사용하는 훅 // App.js import React, { useState } from 'react'; import './App.css' import Greeting from './components/greeting' import Title from './components/title'; const App = () => { const [num, setNum] = useState(0) const onClick = () => { const num_plus = num+1 setNum(num_plus) } return ( ); }; export default App // components/ti.. 2022. 1. 26.