// UVa 10066 - The Twin Towers #include <iostream> using namespace std; int main() { int n, m, t = 0; cin >> n >> m; while (n || m) { t++; int a[101], b[101]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 1; j <= m; j++) cin >> b[j]; int T[101][101]; for (int j = 0; j <= m; j++) T[0][j] = 0; for (int i = 1; i <= n; i++) { T[i][0] = 0; for (int j = 1; j <= m; j++) { if (a[i] == b[j]) T[i][j] = T[i - 1][j - 1] + 1; else T[i][j] = max(T[i - 1][j], T[i][j - 1]); } } cout << "Twin Towers #" << t << endl; cout << "Number of Tiles : " << T[n][m] << endl; cout << endl; cin >> n >> m; } return 0; }
Sunday, June 14, 2015
UVa 10066 - The Twin Towers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment