HDU 1501 Zipper
2016-05-02 14:25
423 查看
记录一下第i个放入之后可能分割的情况,然后可以推出放入第i+1个的分割情况。
#include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<map> #include<algorithm> using namespace std; const int maxn=500; char s1[maxn],s2[maxn],s[maxn]; struct X { int A,B; X(int a,int b) { A=a; B=b; } }; int main() { int T; scanf("%d",&T); for(int Case=1;Case<=T;Case++) { memset(s1,0,sizeof s1); memset(s2,0,sizeof s2); memset(s,0,sizeof s); scanf("%s%s%s",s1,s2,s); queue<X>Q[2]; int now=0; map<int,bool>m; int lenA=strlen(s1),lenB=strlen(s2),lenS=strlen(s); m[0]=1; Q[now].push(X(0,0)); for(int i=0;s[i];i++) { m.clear(); now=now^1; while(!Q[now^1].empty()) { X head=Q[now^1].front(); Q[now^1].pop(); if(s1[head.A]==s[i]&&head.B+lenS-i>=lenB&&m[head.A+1]==0){ Q[now].push(X(head.A+1,head.B)); m[head.A+1]=1; } if(s2[head.B]==s[i]&&head.A+lenS-i>=lenA&&m[head.A]==0){ Q[now].push(X(head.A,head.B+1)); m[head.A]=1; } } } int ans=0; while(!Q[now].empty()) { X head=Q[now].front(); Q[now].pop(); if(head.A==lenA&&head.B==lenB) ans=1; } printf("Data set %d: ",Case); if(ans==1) printf("yes\n"); else printf("no\n"); } return 0; }
相关文章推荐
- 《构建之法》第6~7章读后感和对Scrum的理解
- html常用标签补充
- python lambda函数基础
- 迟到N久的开博
- 【杭电oj】1556 - Color the ball(区间更新)
- RxJava结合ProgressDialog实现请求数据
- EntityFramework之一对一关系(二)
- Scrum团队成立
- Android Tween Animation XML文件中标签的使用
- Android官方开发文档Training系列课程中文版:打印内容之图像打印
- IOS常见的加密方法,常用的MD5和Base64
- IOS常见的加密方法,常用的MD5和Base64
- ubuntu 上apt-get 安装 php5.6过程和nginx php-fpm 502 问题
- 打印流的使用
- 黑色遮罩引导蒙版 CSS实现方式
- N-01. 网线连接登录 ❀ 网康 (NETENTSEC) 防火墙
- C语言打印9*9乘法口诀表
- C#设计模式学习笔记(一) 之 简单工厂模式
- 内存操作流(处理临时信息)
- 分布式存储初认识——竹子整理