1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <bits/stdc++.h> #define ll long long #define int long long #define double long double #define N 105 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define rrep(i,l,r) for(int i=l;i<r;i++) #define pii pair<int,int> #define x first #define y second using namespace std; int n,m,dp[N][N],a[N],b[N],cnt = 0;
signed main(){ while(cin>>n>>m){ if(!n && !m)break; cnt+=1; cout<<"Twin Towers #"<<cnt<<endl; memset(dp,0,sizeof(dp)); rep(i,1,n)cin>>a[i]; rep(i,1,m)cin>>b[i]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(a[i]==b[j]){ dp[i][j] = dp[i-1][j-1]+1; } else dp[i][j] = max(dp[i-1][j],dp[i][j-1]); } } cout<<"Number of Tiles : "; cout<<dp[n][m]<<endl; } }
|