Skip to content

Commit 5c37941

Browse files
authored
[20250220] BOJ / G5 / 문자열 복사 / 권혁준
1 parent d6fcd71 commit 5c37941

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
```python
2+
3+
S = input()
4+
P = input()
5+
6+
dp = [0 for _ in range(len(P))]
7+
for i in range(len(P)):
8+
if P[:i+1] in S:
9+
dp[i] = 1
10+
continue
11+
12+
j = 1
13+
dp[i] = i+1
14+
while i-j>=0:
15+
16+
if P[i-j+1:i+1] not in S:
17+
break
18+
19+
dp[i] = min(dp[i], dp[i-j] + 1)
20+
j+=1
21+
22+
print(dp[len(P)-1])
23+
24+
```

0 commit comments

Comments
 (0)