Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 60;
- char str1[N + 1], str2[N + 1], str3[N + 1], str4[N + 1];
- int dp[N + 1][N + 1][N + 1][N + 1];
- int main(){
- scanf(" %s %s %s %s", str1, str2, str3, str4);
- int len1 = strlen(str1);
- int len2 = strlen(str2);
- int len3 = strlen(str3);
- int len4 = strlen(str4);
- for(int i1 = 1; i1 <= len1; ++i1){
- for(int i2 = 1; i2 <= len2; ++i2){
- for(int i3 = 1; i3 <= len3; ++i3){
- for(int i4 = 1; i4 <= len4; ++i4){
- if(str1[i1 - 1] == str2[i2 - 1] && str2[i2 - 1] == str3[i3 - 1] && str3[i3 - 1] == str4[i4 - 1]){
- dp[i1][i2][i3][i4] = 1 + dp[i1 - 1][i2 - 1][i3 - 1][i4 - 1];
- } else {
- dp[i1][i2][i3][i4] = max(max(dp[i1 - 1][i2][i3][i4], dp[i1][i2 - 1][i3][i4]),
- max(dp[i1][i2][i3 - 1][i4], dp[i1][i2][i3][i4 - 1]));
- }
- }
- }
- }
- }
- cout << dp[len1][len2][len3][len4];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement