[백준]9251번 LCS C++

semi·2022년 10월 6일
0

coding test

목록 보기
54/57

https://www.acmicpc.net/problem/9251

#include <iostream>
#include <string>
using namespace std;

int dp[1001][1001] = { 0, };

int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string str1, str2;
	cin >> str1 >> str2;
	for (int i = 1; i <= str1.size(); i++)
	{
		for (int j = 1; j <= str2.size(); j++)
		{
			if (str1[i - 1] == str2[j - 1])
			{
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	cout << dp[str1.size()][str2.size()];
	return 0;
}

0개의 댓글