Advertisement
farsid

Untitled

Jul 25th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #define filer() freopen("in.txt","r",stdin)
  2. #define filew() freopen("out.txt","w",stdout)
  3. #define SET(a, x) memset((a), (x), sizeof(a))
  4. #define i64 long long
  5. #include<iostream>
  6. #include<stdio.h>
  7. #include<string.h>
  8. #include<math.h>
  9. #include<algorithm>
  10. #include<queue>
  11. #include<stack>
  12. #include<vector>
  13. #include <map>
  14. #define INF 1<<29
  15.  
  16. using namespace std;
  17.  
  18. char str1[40],str2[40];
  19.  
  20. int len1,len2,len;
  21.  
  22. int DP1[35][35][70];
  23.  
  24. int func1(int i,int j,int L)
  25. {
  26. if(DP1[i][j][L]!=-1)return DP1[i][j][L];
  27.  
  28. if(i==len1 && j==len2)return L;
  29.  
  30. if(i==len1)return func1(i,j+1,L+1);
  31.  
  32. if(j==len2)return func1(i+1,j,L+1);
  33.  
  34. if(str1[i]==str2[j])return func1(i+1,j+1,L+1);
  35.  
  36. return min(func1(i+1,j,L+1),func1(i,j+1,L+1));
  37. }
  38.  
  39. i64 DP[35][35][70];
  40.  
  41. i64 func(int i,int j,int L)
  42. {
  43. if(DP[i][j][L]!=-1)return DP[i][j][L];
  44. if(L==len)
  45. {
  46. if(i==len1 && j==len2)return 1;
  47. else return 0;
  48. }
  49.  
  50. if(i==len1)return func(i,j+1,L+1);
  51.  
  52. if(j==len2)return func(i+1,j,L+1);
  53.  
  54. if(str1[i]==str2[j])return func(i+1,j+1,L+1);
  55.  
  56. return func(i+1,j,L+1)+func(i,j+1,L+1);
  57. }
  58.  
  59. int main()
  60. {
  61. int T,cas=0,i,j,k;
  62. i64 ans;
  63. scanf("%d",&T);
  64. while(T--)
  65. {
  66. //SET(DP1,-1);
  67. //SET(DP,-1);
  68. for(i=0;i<34;i++)
  69. {
  70. for(j=0;j<34;j++)
  71. {
  72. for(k=0;k<65;k++){DP1[i][j][k]=-1;DP[i][j][k]=-1;}
  73. }
  74. }
  75. scanf("%s%s",str1,str2);
  76. len1=strlen(str1);
  77. len2=strlen(str2);
  78.  
  79. len=func1(0,0,0);
  80. //printf("%d\n",len);
  81.  
  82. ans=func(0,0,0);
  83. printf("Case %d: %d %lld\n",++cas,len,ans);
  84.  
  85. }
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement