PKU 2192 Zipper
2009-03-27 14:47
197 查看
PKU 2192 Zipper
http://acm.pku.edu.cn/JudgeOnline/problem?id=2192
晚上要讨论的题之一,先A一下
也是LCS的思想,关键是去找状态转移方程
AC CODE:
#include <iostream>
using namespace std;
#define maxlen 205
char a[maxlen]; //行
char b[maxlen]; //列
char str[maxlen*2];
bool recode[maxlen][maxlen] ;
// b a
int main()
{
int i,j,k,n,m,t,l;
while (scanf("%d",&t)!=EOF)
{
for (l=1;l<=t;l++)
{
memset(a+1,NULL,sizeof(a+1));
memset(b+1,NULL,sizeof(b+1));
memset(str+1,NULL,sizeof(str+1));
memset(recode,0,sizeof(recode));
scanf("%s",a+1);
scanf("%s",b+1);
scanf("%s",str+1);
int alen = strlen(a+1);
int blen = strlen(b+1);
recode[0][0] = 1;
for (i=0;i<=blen;i++) //列 b[]
{
for (j=0;j<=alen;j++) //行 a[]
{
if (i==0 && j==0)
{
continue;
}
if (recode[i-1][j] == 0 && recode[i][j-1] == 0 )
{
recode[i][j] = 0;
}
else if ((recode[i-1][j]&&str[i+j]==b[i]) || (recode[i][j-1]&&str[i+j]==a[j]))
{
recode[i][j] = 1;
}
}
}
//---------------------------------------------------
if (recode[blen][alen])
{
printf("Data set %d: yes/n",l);
}
else
{
printf("Data set %d: no/n",l);
}
}
}
return 0;
}
http://acm.pku.edu.cn/JudgeOnline/problem?id=2192
晚上要讨论的题之一,先A一下
也是LCS的思想,关键是去找状态转移方程
AC CODE:
#include <iostream>
using namespace std;
#define maxlen 205
char a[maxlen]; //行
char b[maxlen]; //列
char str[maxlen*2];
bool recode[maxlen][maxlen] ;
// b a
int main()
{
int i,j,k,n,m,t,l;
while (scanf("%d",&t)!=EOF)
{
for (l=1;l<=t;l++)
{
memset(a+1,NULL,sizeof(a+1));
memset(b+1,NULL,sizeof(b+1));
memset(str+1,NULL,sizeof(str+1));
memset(recode,0,sizeof(recode));
scanf("%s",a+1);
scanf("%s",b+1);
scanf("%s",str+1);
int alen = strlen(a+1);
int blen = strlen(b+1);
recode[0][0] = 1;
for (i=0;i<=blen;i++) //列 b[]
{
for (j=0;j<=alen;j++) //行 a[]
{
if (i==0 && j==0)
{
continue;
}
if (recode[i-1][j] == 0 && recode[i][j-1] == 0 )
{
recode[i][j] = 0;
}
else if ((recode[i-1][j]&&str[i+j]==b[i]) || (recode[i][j-1]&&str[i+j]==a[j]))
{
recode[i][j] = 1;
}
}
}
//---------------------------------------------------
if (recode[blen][alen])
{
printf("Data set %d: yes/n",l);
}
else
{
printf("Data set %d: no/n",l);
}
}
}
return 0;
}
相关文章推荐
- pku2192---Zipper(动态规划题,随机组合两个字符串)
- PKU2192 Zipper(DP+记忆化)
- pku 2192 Zipper
- poj_2192Zipper
- POJ 2192 Zipper
- HDU 1501 & POJ 2192 Zipper(dp记忆化搜索)
- poj 2192 Zipper
- TOJ 3445 POJ 2192 Zipper
- (字符串模式匹配4.7.10)POJ 2192 Zipper(判断第3个字符串能否有前两个字符串组成)
- ACM POJ 2192 Zipper
- POJ 2192 Zipper
- poj_2192Zipper
- poj_2192Zipper
- POJ 2192 Zipper (DFS / DP)
- POJ 2192 Zipper
- POJ 2192 Zipper
- HDU-1501 (POJ-2192) Zipper (DFS||DP)
- 【POJ 2192 Zipper】+ 贪心 + 字符匹配
- poj 2192 Zipper
- [简单DP] POJ 2192 Zipper