Advertisement
mickypinata

SMMR-T107: Magic Spell I

Jul 26th, 2021
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 60;
  5.  
  6. char str1[N + 1], str2[N + 1], str3[N + 1], str4[N + 1];
  7. int dp[N + 1][N + 1][N + 1][N + 1];
  8.  
  9. int main(){
  10.  
  11.     scanf(" %s %s %s %s", str1, str2, str3, str4);
  12.     int len1 = strlen(str1);
  13.     int len2 = strlen(str2);
  14.     int len3 = strlen(str3);
  15.     int len4 = strlen(str4);
  16.     for(int i1 = 1; i1 <= len1; ++i1){
  17.         for(int i2 = 1; i2 <= len2; ++i2){
  18.             for(int i3 = 1; i3 <= len3; ++i3){
  19.                 for(int i4 = 1; i4 <= len4; ++i4){
  20.                     if(str1[i1 - 1] == str2[i2 - 1] && str2[i2 - 1] == str3[i3 - 1] && str3[i3 - 1] == str4[i4 - 1]){
  21.                         dp[i1][i2][i3][i4] = 1 + dp[i1 - 1][i2 - 1][i3 - 1][i4 - 1];
  22.                     } else {
  23.                         dp[i1][i2][i3][i4] = max(max(dp[i1 - 1][i2][i3][i4], dp[i1][i2 - 1][i3][i4]),
  24.                                                  max(dp[i1][i2][i3 - 1][i4], dp[i1][i2][i3][i4 - 1]));
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.     }
  30.     cout << dp[len1][len2][len3][len4];
  31.  
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement