比赛 |
20120703 |
评测结果 |
RRRRRRRRRR |
题目名称 |
旅行 |
最终得分 |
0 |
用户昵称 |
CC |
运行时间 |
0.002 s |
代码语言 |
C++ |
内存使用 |
36.31 MiB |
提交时间 |
2012-07-03 11:52:20 |
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <cstring>
#define INF 1027423549
int T,n,m,o;
int f[3000][3000];
char a[3000],b[3000],c[3000];
bool pan(int pos,int len) {
for (int i = 0;i < len;i++)
if (a[pos + i] != c[i + 1]) return 0;
return 1;
}
int main() {
freopen("dna.in","r",stdin);
freopen("dna.out","w",stdout);
scanf("%d", &T);
while (T--) {
scanf("%s",a + 1);
scanf("%s",b + 1);
n = std::strlen(a + 1);
m = std::strlen(b + 1);
memset(f,61,sizeof(f));
memset(f[0],0,sizeof(f[0]));
for (int i = 1;i <= m;i++)
for (int j = 0;j < i;j++)
for (int k = 0;k <= n;k++)
if (f[j][k] != INF) {
o = 0;
memset(c,0,sizeof(c));
for (int u = j + 1;u <= i;u++) c[++o] = b[u];
for (int u = k + 1;u <= n;u++)
if (pan(u,o))
f[i][u] = std::min(f[i][u],f[j][k] + 2);
}
int ans = INF;
for (int i = 1;i <= n;i++)
ans = std::min(ans,f[m][i]);
if (ans == INF) ans = -1;
printf("%d\n", ans);
}
return 0;
}