I tried the problem 111 of ACM UVA, History Grading...
http://uva.onlinejudge.org/external/1/111.html
But in the case:
10
3 1 2 4 9 5 10 6 8 7
1 2 3 4 5 6 7 8 9 10
4 7 2 3 10 6 9 1 5 8
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6
I get
6
4
10
5
And the solution it´s :
9
5
10
9
Why???
Here it´s my code:
#include<stdio.h>
#include<iostream>
using namespace std;
int n,numeros1[30],numeros2[30],matriz[31][31];
int LCS1(int x){
int i,j;
for(i=0;i<=x;i++){
matriz[i][0]=0;
matriz[0][i]=0;
}
for(i=1;i<=x;i++)
for(j=1;j<=x;j++)
if(numeros1[i-1]==numeros2[j-1])
matriz[i][j]=1+matriz[i-1][j-1];
else
matriz[i][j]=max(matriz[i-1][j],matriz[i][j-1]);
return matriz[x][x];
}
int main(void){
int i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&numeros1[i]);
while(scanf("%d",&numeros2[0])!=EOF){
for(i=1;i<n;i++)
scanf("%d",&numeros2[i]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
matriz[i][j]=0;
printf("%d\n",LCS1(n));
}
return 0;
}
--
Victor Manuel Grijalva Altamirano
Universidad Tecnologica de La Mixteca
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.