江南小巫 @ 2018-01-28 16:45:12
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#define M(a) memset(a,0,sizeof a)
#define fo(j,n) for(i=j;i<=n;i++)
#define MOD 1000000007
#define ll long long
using namespace std;
int a[105],b[105];
int dp[105][105];
int n,i,j;
int main(){
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&a[i]);
for(i=1;i<=n;i++)scanf("%d",&b[i]);
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(a[i]==b[i])dp[i][j]=dp[i-1][j-1]+1;
else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
printf("%d\n",dp[n][n]);
return 0;
}
by Wolfycz @ 2018-01-28 17:52:32
你写
应该写
by HuangBo @ 2018-03-15 16:48:21
呵呵一笑———这是纯O(N^2)算法吧...