Skip to content

Commit

Permalink
23-yuyu0830
Browse files Browse the repository at this point in the history
23-yuyu0830
  • Loading branch information
yuyu0830 authored Aug 17, 2024
2 parents 67538f5 + 0e159c4 commit e8cee2a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions yuyu0830/LCS/9252.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <string>

using namespace std;

int arr[1001][1001] = {0, };
string str1, str2;

void print(int x, int y) {
if (!arr[x][y]) return;

if (str1[x - 1] == str2[y - 1]) {
print(x - 1, y - 1);
printf("%c", str1[x - 1]);
return;
}

arr[x - 1][y] > arr[x][y - 1] ? print(x - 1, y) : print(x, y - 1);
}

int main() {
cin >> str1 >> str2;

int len1 = str1.size(), len2 = str2.size();

for (int i = 0; i <= len1; i++) {
for (int j = 0; j <= len2; j++) {
if (!i || !j) arr[i][j] = 0;
else if (str1[i - 1] == str2[j - 1]) arr[i][j] = arr[i - 1][j - 1] + 1;
else arr[i][j] = max(arr[i][j - 1], arr[i - 1][j]);
}
}

printf("%d\n", arr[len1][len2]);
print(len1, len2);
}
1 change: 1 addition & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
| 19์ฐจ์‹œ | 2024.07.12 | ์žฌ๊ท€ | [์šฐ์ˆ˜๋งˆ์„](https://www.acmicpc.net/problem/1949) | - |
| 20์ฐจ์‹œ | 2024.07.22 | LIS | [๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 5](https://www.acmicpc.net/problem/14003) | - |
| 21์ฐจ์‹œ | 2024.07.23 | ์ˆ˜ํ•™ | [1์˜ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ](https://www.acmicpc.net/problem/9527) | - |
| 23์ฐจ์‹œ | 2024.08.05 | LCS | [LCS 2](https://www.acmicpc.net/problem/9252) | - |
---

0 comments on commit e8cee2a

Please sign in to comment.