#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
const int MAX = 101;
string s1, s2, s3;
int maxlong[MAX][MAX][MAX];
struct Move {
int x, y, z;
};
Move mv[7] = { {1,0,0}, {1,0,1}, {1,1,0}, {0,1,1}, {0,1,0}, {0,0,0}, {0,0,1} };
int maxstr(int i, int j, int k) {
if (i >= s1.size() || j >= s2.size() || k >= s3.size())
return 0;
int &answer = maxlong[i][j][k];
if (answer != -1)
return answer;
answer = maxstr(i + 1, j + 1, k + 1) + (s1[i] == s2[j] && s2[j] == s3[k]);
for (int index = 0; index < 7; index++)
answer = max(answer, maxstr(i + mv[index].x, j + mv[index].y, k + mv[index].z));
return answer;
}
int main(void) {
cin >> s1 >> s2 >> s3;
memset(maxlong, -1, sizeof(maxlong));
cout << maxstr(0, 0, 0) << endl;
return 0;
}
'백준 알고리즘 > 다이나믹 프로그래밍' 카테고리의 다른 글
백준 1328번 C++ (0) | 2019.08.25 |
---|---|
백준 10835번 C++ (0) | 2019.08.24 |
백준 2225번 C++ (0) | 2019.08.24 |
백준 11054번 C++ (0) | 2019.08.24 |
백준 10942번 C++ (0) | 2019.08.23 |