1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <algorithm>

int main()
{
    int n, m, q;
    char s[3001];
    char t[3001];
    
    scanf("%d%d%d", &n, &m, &q);
    scanf("%s%s", s, t);
    
    while (q--)
    {
        int i, j, k, l;
        static int DP[3001][3001];
        
        scanf("%d%d%d%d", &i, &j, &k, &l);
        
        for (int it1 = 0; i + it1 <= j; it1++)
            for (int it2 = 0; k + it2 <= l; it2++)
                if (s[i + it1-1] == t[k + it2-1])
                    DP[it1+1][it2+1] = DP[it1][it2] + 1;
                else
                    DP[it1+1][it2+1] = std::max(DP[it1+1][it2], DP[it1][it2+1]);
        
        printf("%d\n", DP[j-i+1][l-k+1]);
    }
    
    return 0;
}