uva 111 - History Grading Solution


uva 111 - History Grading Solution 


#include<iostream>
#include<algorithm>

using namespace std;

int calculate_lis(int *arr1,int *arr2,int n){
int i, j, k;
int lis[25][25];
for (i = 0; i <= n; i++){
lis[i][0] = 0;
lis[0][i] = 0;
}
for (i = 0; i < n; i++){
for (j = 0; j < n; j++){
if (arr1[i] == arr2[j]){
lis[i + 1][j + 1] = lis[i][j] + 1;
}
else{
lis[i + 1][j + 1] = max(lis[i][j + 1], lis[i + 1][j]);
}
}
}
return lis[n][n];
}
int main(){
int correct_order[25], rank[20],i,j,n,x;
cin >> n;
for (i = 0; i <n; i++){
cin >> x;
x--;
correct_order[x] = i;
}
while (cin >> x){
x--;
rank[x] = 0;
for (i = 1; i < n; i++){
cin >> x;
x--;
rank[x] = i;
}
cout << calculate_lis(correct_order, rank, n) << endl;
}
return 0;
}

Comments

Popular posts from this blog

uva 679 - Dropping Balls Solution

uva 481 - What Goes Up Solution

uva-10077 Solution --- The Stern-Brocot Number System