Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define filer() freopen("in.txt","r",stdin)
- #define filew() freopen("out.txt","w",stdout)
- #define SET(a, x) memset((a), (x), sizeof(a))
- #define i64 long long
- #include<iostream>
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- #include<algorithm>
- #include<queue>
- #include<stack>
- #include<vector>
- #include <map>
- #define INF 1<<29
- using namespace std;
- char str1[40],str2[40];
- int len1,len2,len;
- int DP1[35][35][70];
- int func1(int i,int j,int L)
- {
- if(DP1[i][j][L]!=-1)return DP1[i][j][L];
- if(i==len1 && j==len2)return L;
- if(i==len1)return func1(i,j+1,L+1);
- if(j==len2)return func1(i+1,j,L+1);
- if(str1[i]==str2[j])return func1(i+1,j+1,L+1);
- return min(func1(i+1,j,L+1),func1(i,j+1,L+1));
- }
- i64 DP[35][35][70];
- i64 func(int i,int j,int L)
- {
- if(DP[i][j][L]!=-1)return DP[i][j][L];
- if(L==len)
- {
- if(i==len1 && j==len2)return 1;
- else return 0;
- }
- if(i==len1)return func(i,j+1,L+1);
- if(j==len2)return func(i+1,j,L+1);
- if(str1[i]==str2[j])return func(i+1,j+1,L+1);
- return func(i+1,j,L+1)+func(i,j+1,L+1);
- }
- int main()
- {
- int T,cas=0,i,j,k;
- i64 ans;
- scanf("%d",&T);
- while(T--)
- {
- //SET(DP1,-1);
- //SET(DP,-1);
- for(i=0;i<34;i++)
- {
- for(j=0;j<34;j++)
- {
- for(k=0;k<65;k++){DP1[i][j][k]=-1;DP[i][j][k]=-1;}
- }
- }
- scanf("%s%s",str1,str2);
- len1=strlen(str1);
- len2=strlen(str2);
- len=func1(0,0,0);
- //printf("%d\n",len);
- ans=func(0,0,0);
- printf("Case %d: %d %lld\n",++cas,len,ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement