1 条题解
-
0
C++ :
#include<bits/stdc++.h> #define ll long long #define sqr(x) ((x)*(x)) #define mp make_pair #define pb push_back #define fi first #define se second #define rep(i,x,y) for(int i=(x);i<=(y);i++) #define vi vector<int> #define vl vector<ll> #define vs vector<string> #define pii pair<int,int> #define pdd pair<double,double> #define vpii vector< pii > #define SZ(x) ((int)(x).size()) #define MS(x,y) memset(x,y,sizeof(x)) #define ls (rt<<1) #define rs (rt<<1|1) const double pi=acos(-1); const int N=55; const int MOD=1e9+7; const double eps=1e-7; using namespace std; template<class T>inline bool rd(T &num) { char in=getchar();bool ok=false; if(in==EOF) return false; while(in!='-'&&(in<'0'||in>'9')) in=getchar(); if(in=='-'){ok=true;num=0;} else num=in-'0'; while(in=getchar(),in>='0'&&in<='9'){num*=10,num+=in-'0';} if(ok) num=-num; return true; } char a[N],b[N]; bool dp[N][N][N][N]; int n,m; int main() { //freopen("in.txt","r",stdin); int T; rd(T); while(T--) { scanf("%s%s",a+1,b+1); n=strlen(a+1),m=strlen(b+1); int ans=0; rep(len1,0,n) { rep(len2,0,m) { for(int i=1,j=len1;j<=n;i++,j++) { for(int k=1,l=len2;l<=m;k++,l++) { if(len1+len2<=1) dp[i][j][k][l]=true; else { dp[i][j][k][l]=false; if(a[i]==a[j]&&len1>1) dp[i][j][k][l]|=dp[i+1][j-1][k][l]; if(a[i]==b[l]&&len1&&len2) dp[i][j][k][l]|=dp[i+1][j][k][l-1]; if(b[k]==a[j]&&len1&&len2) dp[i][j][k][l]|=dp[i][j-1][k+1][l]; if(b[k]==b[l]&&len2>1) dp[i][j][k][l]|=dp[i][j][k+1][l-1]; } if(dp[i][j][k][l]) ans=max(ans,len1+len2); } } } } printf("%d\n",ans); } }
- 1
信息
- ID
- 1006
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者