K_order subsequence problem

what is wrong in this code it is not submitting on hackerearth.
#include<bits/stdc++.h>
#include
using namespace std;
#define ll long long
#define F(i,a,b) for(ll i=0;i<=n-1;i++)
ll dp[2222][2222][9];
ll a[2222],b[2222],m,n;

ll f(ll i,ll j,ll k){
if(i==n || j==m)
return 0;
if(dp[i][j][k]!=-1)
return dp[i][j][k];
ll res=0;
if(a[i]==b[j]){res=1+f(i+1,j+1,k);}
else{if(k>0) res=1+f(i+1,j+1,k-1);
res=max(res,f(i,j+1,k));
res=max(res,f(i+1,j,k));}
return dp[i][j][k]=res;
}
int main()
{
memset(dp,-1,sizeof(dp));
ll k;
cin>>n>>m>>k;
F(i,0,n-1)
cin>>a[i];

F(j,0,m-1)
cin>>b[j];
ll ans=f(0,0,k);
  cout<<ans;

}

HEllo @anujkurmi,

Please, share your code using Online Coding Blocks IDE.
The way you have shared it, is introducing many syntax errors in the code.

Steps:

  1. Paste your code on IDE.
  2. Save it there.
  3. Share the URL generated.

There are two issues with your code:

  1. The macro you have defined for “for loop” is wrong:
    #define F(i,a,b) for(ll i=a;i<=n-1;i++)
    What is the use of a and b?

  2. On submitting your code, it is exceeding the memory limit.

I have modified your code:

Hope, this would help.
Give a like, if you are satisfied.