标签:
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <climits> #include <cstring> #include <cmath> #include <map> #include <set> #define INF 100000000 using namespace std; int a[1005]; int b[1005]; int dp[1005][1005]; int main(){ int n,m; int k = 1; while(cin >> n >> m,n||m){ for(int i = 0;i < n;i++){ scanf("%d",&a[i]); } for(int i = 0;i < m;i++){ scanf("%d",&b[i]); } //memset(dp,0,sizeof(dp)); for(int i = 0;i < n;i++){ for(int j = 0;j < m;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\n",k++); printf("Number of Tiles: %d\n\n",dp[n][m]); } return 0; }
标签:
原文地址:http://blog.csdn.net/qq_24667639/article/details/45343837