generated from cotes2020/chirpy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: 🐣 공통 부분 문자열 | ||
author: olive-su | ||
date: 2023-12-10 20:00:00 +09:00 | ||
categories: [알고리즘, 공통 부분 문자열] | ||
tags: [알고리즘, 백준, 골드5, DP, 8주차, 김수경] | ||
render_with_liquid: false | ||
--- | ||
|
||
## 1. 문제 링크 | ||
|
||
[공통 부분 문자열](https://www.acmicpc.net/problem/5582) | ||
|
||
<br> | ||
|
||
## 2. 코드 | ||
|
||
```python | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
fir_str = input().rstrip() | ||
sec_str = input().rstrip() | ||
|
||
dp = [[0 for _ in range(len(fir_str) + 1)] for _ in range(len(sec_str) + 1)] | ||
|
||
for i in range(len(sec_str)): | ||
for j in range(len(fir_str)): | ||
if sec_str[i] == fir_str[j]: | ||
dp[i + 1][j + 1] = dp[i][j] + 1 | ||
|
||
answer = 0 | ||
for d in dp: | ||
answer = max(answer, max(d)) | ||
print(answer) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: 🐣 상담원 인원 | ||
author: olive-su | ||
date: 2023-12-10 20:00:00 +09:00 | ||
categories: [알고리즘, 상담원 인원] | ||
tags: [알고리즘, 프로그래머스, level2, 완전탐색, 8주차, 김수경] | ||
render_with_liquid: false | ||
--- | ||
|
||
## 1. 문제 링크 | ||
|
||
[상담원 인원](https://school.programmers.co.kr/learn/courses/30/lessons/214288) | ||
|
||
<br> | ||
|
||
## 2. 코드 | ||
|
||
```python | ||
# FIFO | ||
# 각 멘토당 끝나는 시간 기록 | ||
# 끝나는 시간이 더 빠른 멘토에게 상담 진행 | ||
# 우선 멘토 한명씩 배정하고 이후, 기다리는 시간이 가장 긴 팀에게 멘토 추가 배정 | ||
|
||
def min_time(start_time, end_time, group_queue): | ||
wait_time = 0 | ||
min_v = int(1e9) | ||
target_idx = 0 | ||
|
||
for i in range(len(group_queue)): | ||
if group_queue[i] <= start_time: | ||
target_idx = i | ||
min_v = 0 | ||
break | ||
# 시간차가 최소가 되는 값 찾기 | ||
if min_v > group_queue[i] - start_time: | ||
target_idx = i | ||
min_v = group_queue[i] - start_time | ||
|
||
group_queue[target_idx] = max(start_time, group_queue[target_idx]) + end_time # 끝나는 시간으로 바꿔줌 | ||
wait_time = min_v | ||
|
||
return wait_time, group_queue | ||
|
||
|
||
def solution(k, n, reqs): | ||
answer = 0 | ||
wait_queue = [[0] for _ in range(k + 1)] | ||
n = n - k | ||
|
||
while n >= 0: | ||
wait_time = [0] * (k + 1) # 각 그룹별로 기다려야 하는 시간 총합 | ||
for start, end, g in reqs: | ||
t, q = min_time(start, end, wait_queue[g]) | ||
wait_time[g] += t | ||
wait_queue[g] = q | ||
|
||
max_time = max(wait_time) # 각 그룹 중 최대로 기다려야하는 그룹의 시간 | ||
wait_queue[wait_time.index(max_time)].append(0) | ||
n -= 1 | ||
for i in range(k + 1): | ||
wait_queue[i] = len(wait_queue[i]) * [0] | ||
|
||
answer = sum(wait_time) | ||
return answer | ||
``` |