UVa 10066 The Twin Towers (DP&LCS)

来源:互联网 发布:傲慢与偏见与僵尸 知乎 编辑:程序博客网 时间:2024/06/05 01:05

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\nNumber of Tiles : %d\n\n", ++cas, dp[n1][n2]);}return 0;}

原创粉丝点击