Welcome

首页 / 软件开发 / 数据结构与算法 / UVa 10066 The Twin Towers:DP&LCS

UVa 10066 The Twin Towers:DP&LCS2014-07-28 csdn博客 synapse7

10066 - The Twin Towers

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=1007

水。

完整代码:

/*0.012s*/#include<bits/stdc++.h>using namespace std;int a[105], b[105];int dp[105][105];int main(){int n1, n2, i, j, cas = 0;while (scanf("%d%d", &n1, &n2), n1){for (i = 0; i < n1; ++i) scanf("%d", &a[i]);for (i = 0; i < n2; ++i) scanf("%d", &b[i]);memset(dp, 0, sizeof(dp));for (i = 0; i < n1; ++i)for (j = 0; j < n2; ++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("Twin Towers #%d
Number of Tiles : %d

", ++cas, dp[n1][n2]);}return 0;}