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
#include<bits/stdc++.h>
using namespace std;
int dp[3005][3005];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int a,b,t;
    cin>>a>>b>>t;
    string c,d;
    cin>>c>>d;
    c = "+" + c;
    d = "+" + d;
    while(t--)
    {
        int i,j,k,l;
        cin>>i>>j>>k>>l;
        for(int x=i;x<=j;x++)
            for(int y=k;y<=l;y++)
                dp[x][y] = max({dp[x-1][y] , dp[x][y-1] , dp[x-1][y-1] + (c[x] == d[y])});
        cout<<dp[j][l]<<'\n';
        for(int x=i;x<=j;x++)
            for(int y=k;y<=l;y++)
                dp[x][y] = 0;
    }
	return 0;
}