My issue
explain where i m wrong
My code
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int x,y,count=0;
cin>>x>>y;
int a[x],b[y];
for(int i=0;i<x;i++){
cin>>a[i];
for(int j=0;j<y;j++){
cin>>b[j];
if(a[i]==b[j]){
count=count+1;
}
}
}
cout<<count<<endl;
}
// your code goes here
return 0;
}
Problem Link: HALLCON Problem - CodeChef
@drak_byte
Your logic is not right .
Its a dp problem .
Plzz refer my solution for better understanding.
#include <bits/stdc++.h>
using namespace std;
int dp[501][501];
int cal(int a[],int b[],int n,int m,int i,int j)
{
if(i==n||j==m)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
if(a[i]==b[j])
{
return dp[i][j]=1+cal(a,b,n,m,i+1,j+1);
}
else
{
return dp[i][j]=max(cal(a,b,n,m,i+1,j),cal(a,b,n,m,i,j+1));
}
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int a[n];
int b[m];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
memset(dp,-1,sizeof(dp));
cout<<cal(a,b,n,m,0,0)<<endl;
}
return 0;
}
include
using namespace std;
int main() {
int t;
cin>>t;
int x,y,count=0;
while(t–){
cin>>x>>y;
int a[x],b[y],i,j;
for(i=0;i<x;i++){
cin>>a[i];
}
for( j=0;j<y;j++){
cin>>b[j];
}
if(a[i]==b[j]){
count=count+1;
}
}
cout<<count<<endl;
// your code goes here
return 0;
}