baekjoon 20260415
This commit is contained in:
parent
7a2f8750f6
commit
6270575be8
@ -1,30 +1,27 @@
|
|||||||
s = input().rstrip()
|
S = input().rstrip()
|
||||||
l = len(s)
|
L = len(S)
|
||||||
|
|
||||||
isPalindrom = [[False]*l for _ in range(l)]
|
isPal = [[False]*L for _ in range(L)]
|
||||||
for length in range(1,l+1) :
|
for i in range(L) :
|
||||||
for start in range(l-length + 1) :
|
isPal[i][i] = True
|
||||||
end = start + length - 1
|
if i != 0 and S[i] == S[i-1] :
|
||||||
|
isPal[i-1][i] = True
|
||||||
|
|
||||||
if length == 1 :
|
for l in range(3, L+1) :
|
||||||
isPalindrom[start][end] = True
|
for start in range(L-l+1) :
|
||||||
|
end = start + l - 1
|
||||||
|
|
||||||
elif length == 2 :
|
if S[start] == S[end] and isPal[start+1][end-1] :
|
||||||
if s[start] == s[end] :
|
isPal[start][end] = True
|
||||||
isPalindrom[start][end] = True
|
|
||||||
else :
|
|
||||||
if s[start] == s[end] and isPalindrom[start+1][end-1]:
|
|
||||||
isPalindrom[start][end] = True
|
|
||||||
|
|
||||||
dp = [2501]*l
|
dp = [L+1] * L
|
||||||
|
|
||||||
for end in range(l) :
|
for end in range(l) :
|
||||||
for start in range(end+1) :
|
for start in range(end+1) :
|
||||||
if isPalindrom[start][end] :
|
if isPal[start][end] :
|
||||||
if start == 0 :
|
if start == 0 :
|
||||||
dp[end] = 1
|
dp[end] = 1
|
||||||
else :
|
else :
|
||||||
dp[end] = min(dp[end], dp[start-1] + 1)
|
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