#include <stdio.h>
int C[102][102];
int main() {
int A[102], B[102], I, J, ONE, TWO, MAX, CASES=1;
while (scanf("%d %d",&ONE, &TWO)==2 && ONE && TWO) {
for (I=0 ; I<ONE ; I++) {
scanf("%d",&A[I]);
}
for (I=0 ; I<TWO ; I++) {
scanf("%d",&B[I]);
}
if (TWO>=ONE) MAX = TWO;
else MAX = ONE;
for (I=0 ; I<MAX ; I++) {
C[0][I] = C[I][0] = 0;
}
for (I=1 ; I<=ONE ; I++) {
for (J=1 ; J<=TWO ; J++) {
if (A[I-1] == B[J-1]) {
C[I][J] = C[I-1][J-1] + 1;
} else if (C[I-1][J]>=C[I][J-1]) {
C[I][J] = C[I-1][J];
} else {
C[I][J] = C[I][J-1];
}
}
}
printf("Twin Towers #%d\nNumber of Tiles : ",CASES++);
printf("%d\n\n",C[I-1][J-1]);
}
return 0;
}
Wednesday, September 08, 2010
[UVa] 10066 - The Twin Towers
Algorithms Used: Longest Common Subsequence
Subscribe to:
Post Comments (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
Install MinGW GCC Port on Windows. 1. Just go to this address [ http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/ ]...
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.