-문제:https://www.acmicpc.net/problem/9252

 

-정답풀이: 

LCS와 풀이는 같은데 다만 숫자가 아닌 문자를 dp에 넣으면 된다

x=['']+list(input())
y=['']+list(input())
dp=[['']*len(y) for _ in range(len(x))]

for i in range(1,len(x)):
    for j in range(1,len(y)):
        if x[i]==y[j]:
            dp[i][j]=dp[i-1][j-1]+x[i]
        else:
            if len(dp[i-1][j])>=len(dp[i][j-1]):
                dp[i][j]=dp[i-1][j]
            else:
                dp[i][j]=dp[i][j-1]
result=dp[-1][-1]                
print(len(result))
print(result)

+ Recent posts