baekjoon 20260415
This commit is contained in:
parent
7a2f8750f6
commit
6270575be8
@ -1,30 +1,27 @@
|
||||
s = input().rstrip()
|
||||
l = len(s)
|
||||
S = input().rstrip()
|
||||
L = len(S)
|
||||
|
||||
isPalindrom = [[False]*l for _ in range(l)]
|
||||
for length in range(1,l+1) :
|
||||
for start in range(l-length + 1) :
|
||||
end = start + length - 1
|
||||
isPal = [[False]*L for _ in range(L)]
|
||||
for i in range(L) :
|
||||
isPal[i][i] = True
|
||||
if i != 0 and S[i] == S[i-1] :
|
||||
isPal[i-1][i] = True
|
||||
|
||||
if length == 1 :
|
||||
isPalindrom[start][end] = True
|
||||
for l in range(3, L+1) :
|
||||
for start in range(L-l+1) :
|
||||
end = start + l - 1
|
||||
|
||||
elif length == 2 :
|
||||
if s[start] == s[end] :
|
||||
isPalindrom[start][end] = True
|
||||
else :
|
||||
if s[start] == s[end] and isPalindrom[start+1][end-1]:
|
||||
isPalindrom[start][end] = True
|
||||
if S[start] == S[end] and isPal[start+1][end-1] :
|
||||
isPal[start][end] = True
|
||||
|
||||
dp = [2501]*l
|
||||
dp = [L+1] * L
|
||||
|
||||
for end in range(l) :
|
||||
for start in range(end+1) :
|
||||
if isPalindrom[start][end] :
|
||||
if isPal[start][end] :
|
||||
if start == 0 :
|
||||
dp[end] = 1
|
||||
else :
|
||||
dp[end] = min(dp[end], dp[start-1] + 1)
|
||||
|
||||
print(dp[l-1])
|
||||
|
||||
print(dp[L-1])
|
||||
1
code_study/Baekjoon/python/2443.py
Normal file
1
code_study/Baekjoon/python/2443.py
Normal file
@ -0,0 +1 @@
|
||||
print("\n".join([" "*i + "*"*(2*N-(2*i+1)) for N in [int(input())] for i in range(N)]))
|
||||
Loading…
x
Reference in New Issue
Block a user