Skip to content

Commit bc1bd1b

Browse files
authored
Merge pull request #125 from zaqquum/main
Hongjoo/1월 3주차 /3문제
2 parents 4c61858 + 01dc628 commit bc1bd1b

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

Hongjoo/백준/곱셈.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import sys
2+
a,b,c = map(int,sys.stdin.readline().split())
3+
4+
def multi (a,n):
5+
if n == 1:
6+
return a%c
7+
else:
8+
tmp = multi(a,n//2)
9+
if n %2 ==0:
10+
return (tmp * tmp) % c
11+
else:
12+
return (tmp * tmp *a) %c
13+
14+
print(multi(a,b))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
https://www.acmicpc.net/problem/5582
3+
# 유형 : dp , LCS(longest common sequence)
4+
LCSubstring 특징
5+
1. 무조건 "연속된" 공통 문자열 -> 한번이라도 다르면 dp =0로 초기화,
6+
LCS(subsequence)
7+
- 부분수열은 연속된 값이 아님 -> 최대 공통부분수열은 계속 유지됨
8+
조건
9+
- 한글자씩 비교함
10+
(1) x[j] == y[i] 같으면 -> dp[i][j] = max(대각선 +1 , 위) => dp
11+
(2) 다르면 ->0 ()
12+
13+
"""
14+
import sys
15+
x = list(sys.stdin.readline())[:-1]
16+
y= list(sys.stdin.readline())[:-1]
17+
dp = [[0 for _ in range(len(y))] for j in range(len(x))]
18+
19+
#2. Dp , LCS(longest-common-sequence)
20+
21+
for i in range(len(x)) :
22+
for j in range(len(y)) :
23+
24+
if i== 0 or j== 0 :
25+
if x[i] == y[j] : # 예외 처리
26+
dp[i][j] =1
27+
continue
28+
if x[i] == y[j] :
29+
dp[i][j] =dp[i-1][j-1] +1
30+
else :
31+
dp[i][j] = 0 #dp[i-1][j]
32+
33+
#3. answer이 꼭 뒤로 오지 않음
34+
answer = 0
35+
for i in range(len(x)):
36+
print(dp[i])
37+
answer = max(max(dp[i]),answer)
38+
39+
print(answer)

Hongjoo/백준/받아쓰기.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
백준 #20542. 받아쓰기/DP /골드5
3+
https://www.acmicpc.net/problem/20542
4+
5+
(1) 문자가 같음 -> 대각선 = 현위치
6+
(2) 다른 문자
7+
min (왼쪽[add] , 대각선[edit] , 위) +1
8+
"""
9+
import sys
10+
N , M = map(int, sys.stdin.readline().split())
11+
predict =list(*map(str,sys.stdin.readline().split()))
12+
gt = list(*map(str,sys.stdin.readline().split()))
13+
print(predict , gt)
14+
# predict -> gt
15+
dp = [[0 for _ in range(len(gt)+1)] for k in range(len(predict)+1)]
16+
dp[0] = list(range(len(gt)+1))
17+
print(dp)
18+
for i in range(1,len(predict)+1):
19+
for j in range(len(gt)+1) :
20+
# 초기화
21+
if j==0 :
22+
dp[i][j] = dp[i-1][j]+ 1 # 위 +1
23+
continue
24+
25+
# dp 채우기
26+
if predict[i] == gt[j]:
27+
dp[i][j] = dp[i-1][j-1]
28+
print(f"samep { dp}")
29+
else :
30+
dp[i][j] = 1 + min(dp[i-1][j-1] , dp[i][j-1] , dp[i-1][j])
31+
32+
print(dp)

0 commit comments

Comments
 (0)