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
5 changed files
with
479 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,67 @@ | ||
--- | ||
title: 🐣 가르침 | ||
author: olive-su | ||
date: 2023-12-24 22:00:00 +09:00 | ||
categories: [알고리즘, 가르침] | ||
tags: [알고리즘, 백준, 골드4, 비트마스킹, 10주차, 김수경] | ||
render_with_liquid: false | ||
math: true | ||
--- | ||
|
||
## 1. 문제 링크 | ||
|
||
[1062번: 가르침](https://www.acmicpc.net/problem/1062) | ||
|
||
<br> | ||
|
||
## 2. 코드 | ||
|
||
```python | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
n, k = map(int ,input().split()) | ||
rst = 0 | ||
word = [] | ||
dict = {'a':1, 'n':1, 't':1, 'i':1, 'c':1} # 이미 배운 글자 목록 | ||
k -= 5 | ||
|
||
for \_ in range(n): | ||
inputs = input().rstrip()[4:-4] | ||
word.append(inputs) | ||
for i in inputs: | ||
if i not in dict: | ||
dict[i] = 0 | ||
|
||
dict_keys = list(dict.keys()) | ||
|
||
if len(dict) > 5 and k < 0: | ||
sys.exit(print(0)) | ||
|
||
def dfs(k, idx): | ||
global rst | ||
cnt = 0 | ||
for i in word: # 읽을 수 있는 단어 셈 | ||
flag = 1 | ||
for j in i: | ||
if not dict[j]: # 아직 배우지 않은 글자 | ||
flag = 0 | ||
break | ||
cnt += flag | ||
rst = max(rst, cnt) | ||
|
||
if k: | ||
for i in range(idx, len(dict)): | ||
if dict[dict_keys[i]] == 0: | ||
dict[dict_keys[i]] = 1 | ||
dfs(k-1, i) | ||
dict[dict_keys[i]] = 0 | ||
|
||
dfs(k, 5) | ||
print(rst) | ||
|
||
``` | ||
|
||
``` | ||
``` |
57 changes: 57 additions & 0 deletions
57
_posts/algorithm/가장-긴-바이토닉-부분-수열/2023-12-17-김수경-가장-긴-바이토닉-부분-수열.md
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,57 @@ | ||
--- | ||
title: 🐣 가장 긴 바이토닉 부분 수열 | ||
author: olive-su | ||
date: 2023-12-17 20:00:00 +09:00 | ||
categories: [알고리즘, 가장 긴 바이토닉 부분 수열] | ||
tags: [알고리즘, 백준, 골드4, DP, 9주차, 김수경] | ||
render_with_liquid: false | ||
math: true | ||
--- | ||
|
||
## 1. 문제 링크 | ||
|
||
[11054번: 가장 긴 바이토닉 부분 수열](https://www.acmicpc.net/problem/11054) | ||
|
||
<br> | ||
|
||
## 2. 코드 | ||
|
||
```python | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
n = int(input()) | ||
a = list(map(int, input().split())) | ||
incresed_dp = [0] * n | ||
decresed_dp = [0] * n | ||
|
||
# 좌측에서부터 증가하는 부분 수열 탐색 | ||
for i in range(n): | ||
flag = 0 | ||
for j in range(i - 1, -1, -1): | ||
if a[j] < a[i]: | ||
incresed_dp[i] = incresed_dp[j] + 1 | ||
flag = max(flag, incresed_dp[j] + 1) | ||
if flag: | ||
incresed_dp[i] = flag | ||
else: | ||
incresed_dp[i] = 1 | ||
|
||
# 우측에서부터 증가하는 부분 수열 탐색 | ||
for i in range(n - 1, -1, -1): | ||
flag = 0 | ||
for j in range(i + 1, n): | ||
if a[j] < a[i]: | ||
flag = max(flag, decresed_dp[j] + 1) | ||
if flag: | ||
decresed_dp[i] = flag | ||
else: | ||
decresed_dp[i] = 1 | ||
|
||
|
||
ans = list(map(sum, list(zip(incresed_dp, decresed_dp)))) | ||
print(max(ans) - 1) | ||
|
||
``` | ||
|
||
<br> |
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,50 @@ | ||
--- | ||
title: 🐣 게임 맵 최단거리 | ||
author: olive-su | ||
date: 2023-12-17 20:00:00 +09:00 | ||
categories: [알고리즘, 게임 맵 최단거리] | ||
tags: [알고리즘, 프로그래머스, level2, 구현, 9주차, 김수경] | ||
render_with_liquid: false | ||
math: true | ||
--- | ||
|
||
## 1. 문제 링크 | ||
|
||
[게임 맵 최단거리](https://school.programmers.co.kr/learn/courses/30/lessons/1844) | ||
|
||
<br> | ||
|
||
## 2. 코드 | ||
|
||
```python | ||
from collections import deque | ||
|
||
dx = [-1, 1, 0, 0] | ||
dy = [0, 0, -1, 1] | ||
|
||
def bfs(maps, x, y): | ||
queue = deque() | ||
queue.append((x, y)) | ||
|
||
while queue: | ||
x, y = queue.popleft() | ||
|
||
for i in range(4): | ||
nx = x + dx[i] | ||
ny = y + dy[i] | ||
|
||
if nx < 0 or nx >= len(maps) or ny < 0 or ny >= len(maps[0]): continue | ||
|
||
if maps[nx][ny] == 0: continue | ||
|
||
if maps[nx][ny] == 1: | ||
maps[nx][ny] = maps[x][y] + 1 | ||
queue.append((nx, ny)) | ||
return maps[len(maps)-1][len(maps[0])-1] | ||
|
||
|
||
def solution(maps): | ||
answer = bfs(maps, 0, 0) | ||
print(maps) | ||
return -1 if answer == 1 else answer # 상대 팀 진영에 도착할 수 없을 때 -1 | ||
``` |
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,60 @@ | ||
--- | ||
title: 🐣 보물섬 | ||
author: olive-su | ||
date: 2023-12-24 22:00:00 +09:00 | ||
categories: [알고리즘, 보물섬] | ||
tags: [알고리즘, 백준, 골드5, 그래프, 10주차, 김수경] | ||
render_with_liquid: false | ||
math: true | ||
--- | ||
|
||
## 1. 문제 링크 | ||
|
||
[2589번: 보물섬](https://www.acmicpc.net/problem/2589) | ||
|
||
<br> | ||
|
||
## 2. 코드 | ||
|
||
```python | ||
from collections import deque | ||
|
||
n,m=map(int, input().split()) | ||
maps=[] | ||
for i in range(n): | ||
maps.append(list(input())) | ||
|
||
dx=[1,-1,0,0] | ||
dy=[0,0,1,-1] | ||
|
||
def bfs(i,j): | ||
queue=deque() | ||
queue.append((i,j)) | ||
visited=[[0]*m for _ in range(n)] | ||
visited[i][j]=1 | ||
cnt=0 | ||
while queue: | ||
x,y=queue.popleft() | ||
for i in range(4): | ||
nx=x+dx[i] | ||
ny=y+dy[i] | ||
if nx<0 or nx>=n or ny<0 or ny>=m: | ||
continue | ||
elif maps[nx][ny]=='L' and visited[nx][ny]==0: | ||
visited[nx][ny]=visited[x][y]+1 | ||
cnt=max(cnt,visited[nx][ny]) | ||
queue.append((nx,ny)) | ||
return cnt-1 | ||
|
||
result=0 | ||
for i in range(n): | ||
for j in range(m): | ||
if maps[i][j]=='L': | ||
result=max(result,bfs(i,j)) | ||
|
||
print(result) | ||
``` | ||
|
||
<br> | ||
|
||
## 3. 해설 |
Oops, something went wrong.