UVA 10066 The Twin Towers (LCS)

The Twin Towers

 

LCS水题,就是题读的时候有点费劲。   我英语是渣渣- -!

 

 1 #include <map>
 2 #include <queue>
 3 #include <stack>
 4 #include <math.h>
 5 #include <stdio.h>
 6 #include <string.h>
 7 #include <iostream>
 8 #include <algorithm>
 9 #define LL long long
10 using namespace std;
11 
12 void run()
13 {
14     int n, m;
15     int dp[110][110];
16     int a[110], b[110];
17     int cnt = 0;
18     while(~scanf("%d%d", &n, &m))
19     {
20         cnt++;
21         if(!n && !m)
22             break;
23         for(int i = 1; i <= n; i++)
24             scanf("%d", &a[i]);
25         for(int j = 1; j <= m; j++)
26             scanf("%d", &b[j]);
27         memset(dp, 0, sizeof(dp));
28         for(int i = 1; i <= n; i++)
29         {
30             for(int j = 1; j <= m; j++)
31             {
32                 if(a[i] == b[j])
33                     dp[i][j] = dp[i-1][j-1]+1;
34                 else
35                     dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
36             }
37         }
38         printf("Twin Towers #%d\n", cnt);
39         printf("Number of Tiles : %d\n\n", dp[n][m]);
40     }
41 }
42 
43 int main(void)
44 {
45     run();
46 
47     return 0;
48 }
The Twin Towers

 

posted @ 2013-11-06 09:40  GLSilence  阅读(161)  评论(0编辑  收藏  举报