您的位置:首页 > 其它

uva111 History Grading

2016-07-31 16:57 239 查看
History Grading

Description

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstring>
#include <cctype>
using namespace std;

const int maxn = 32;

int dp[maxn][maxn];

int main() {
int n, x;
scanf("%d", &n);
int a[maxn], b[maxn];
for(int i = 1; i<= n; i++) {
scanf("%d", &x);
a[x] = i;
}
while(scanf("%d", &x) != EOF) {
b[x] = 1;
for(int i = 2; i <= n; i++) {
scanf("%d", &x);
b[x] = i;
}
memset(dp ,0, sizeof(dp));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i] == b[j]){
dp[i+1][j+1] = dp[i][j] + 1;
}else {
dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
}
}
}
printf("%d\n", dp[n+1][n+1]);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: