hdu 4545 魔法串

时间:2021-06-20 14:19:08

http://acm.hdu.edu.cn/showproblem.php?pid=4545

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 2000
using namespace std; char s1[maxn],s2[maxn];
int t,m;
int dp[maxn][maxn];
int g[maxn][maxn]; int main()
{
scanf("%d",&t);
for(int cas=; cas<=t; cas++)
{
scanf("%s",s1+);
scanf("%s",s2+);
scanf("%d",&m);
getchar();
memset(g,,sizeof(g));
for(int i=; i<=m; i++)
{
char ch1,ch2;
scanf("%c %c",&ch1,&ch2);
getchar();
g[ch2-'a'][ch1-'a']=;
}
memset(dp,,sizeof(dp));
int k1=strlen(s1+);
int k2=strlen(s2+);
bool flag=true;
for(int i=; i<=k1; i++)
{
for(int j=; j<=k2; j++)
{
dp[i][j]=max(dp[i-][j],dp[i][j-]);
if(s1[i]==s2[j]||(g[s1[i]-'a'][s2[j]-'a']==))
{
dp[i][j]=max(dp[i][j],dp[i-][j-]+);
}
}
}
printf("Case #%d: ",cas);
if(dp[k1][k2]==k1) printf("happy\n");
else printf("unhappy\n");
}
return ;
}