From 6270575be831c79c02df3fa010ce12831cc5b049 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Wed, 15 Apr 2026 22:43:14 +0900 Subject: [PATCH] baekjoon 20260415 --- code_study/Baekjoon/python/1509.py | 37 ++++++++++++++---------------- code_study/Baekjoon/python/2443.py | 1 + 2 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 code_study/Baekjoon/python/2443.py diff --git a/code_study/Baekjoon/python/1509.py b/code_study/Baekjoon/python/1509.py index 6afa956..001345d 100644 --- a/code_study/Baekjoon/python/1509.py +++ b/code_study/Baekjoon/python/1509.py @@ -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 + +for l in range(3, L+1) : + for start in range(L-l+1) : + end = start + l - 1 - if length == 1 : - isPalindrom[start][end] = True - - 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 - -dp = [2501]*l + if S[start] == S[end] and isPal[start+1][end-1] : + isPal[start][end] = True + +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]) - \ No newline at end of file +print(dp[L-1]) \ No newline at end of file diff --git a/code_study/Baekjoon/python/2443.py b/code_study/Baekjoon/python/2443.py new file mode 100644 index 0000000..247aa6a --- /dev/null +++ b/code_study/Baekjoon/python/2443.py @@ -0,0 +1 @@ +print("\n".join([" "*i + "*"*(2*N-(2*i+1)) for N in [int(input())] for i in range(N)])) \ No newline at end of file