标签:long code memset typedef sizeof syn ace deb max
/*Hatsune Miku 4ever!*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define _for(i,a,b) for(int i = (a);i < b;i ++) #define _rep(i,a,b) for(int i = (a);i > b;i --) #define INF 0x3f3f3f3f #define mod 1000000007 #define lowbit(x) ((x)&(-x)) #define pb push_back #define MIKU 39 #define Design ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define debug() printf("Miku Check OK!\n") #define maxn 339 int n, m; int dp[maxn][maxn]; pair<int,int> path[maxn][maxn]; string s1, s2; string ans; void dfs(int a,int b) { if(!a && !b) return ; if(s1[a]==s2[b]) ans += s1[a]; dfs(path[a][b].first,path[a][b].second); } int main() { Design; s1 += ‘P‘, s2 += ‘M‘; string tmp1, tmp2; cin >> tmp1 >> tmp2; s1 += tmp1, s2 += tmp2; memset(dp,0,sizeof(dp)); int n = s1.size(), m = s2.size(); _for(i,1,n) _for(j,1,m) { if(s1[i]==s2[j]) { if(dp[i-1][j-1]+1 > dp[i][j]) path[i][j] = {i-1,j-1}; dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1); } else { if(dp[i][j-1] > dp[i-1][j]) path[i][j] = {i,j-1}; else path[i][j] = {i-1,j}; dp[i][j] = max(dp[i][j-1],dp[i-1][j]); } } cout << dp[n-1][m-1] << endl; dfs(n-1,m-1); reverse(ans.begin(),ans.end()); cout << ans << endl; return 0; }
标签:long code memset typedef sizeof syn ace deb max
原文地址:https://www.cnblogs.com/Asurudo/p/14153585.html