zipper dp与dfs poj4710
来源:互联网 发布:中药软件哪个好使 编辑:程序博客网 时间:2024/05/22 10:30
PageWeb ContestsProblemsRanklistStatusStatisticsZipper
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 25 Accepted Submission(s) : 11
Problem Description
Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order.
For example, consider forming "tcraete" from "cat" and "tree":
String A: cat
String B: tree
String C: tcraete
As you can see, we can form the third string by alternating characters from the two strings. As a second example, consider forming "catrtee" from "cat" and "tree":
String A: cat
String B: tree
String C: catrtee
Finally, notice that it is impossible to form "cttaree" from "cat" and "tree".
For example, consider forming "tcraete" from "cat" and "tree":
String A: cat
String B: tree
String C: tcraete
As you can see, we can form the third string by alternating characters from the two strings. As a second example, consider forming "catrtee" from "cat" and "tree":
String A: cat
String B: tree
String C: catrtee
Finally, notice that it is impossible to form "cttaree" from "cat" and "tree".
Input
The first line of input contains a single positive integer from 1 through 1000. It represents the number of data sets to follow. The processing for each data set is identical. The data sets appear on the following lines, one data set per line. For each data set, the line of input consists of three strings, separated by a single space. All strings are composed of upper and lower case letters only. The length of the third string is always the sum of the lengths of the first two strings. The first two strings will have lengths between 1 and 200 characters, inclusive.
Output
For each data set, print: Data set n: yes if the third string can be formed from the first two, or Data set n: no if it cannot. Of course n should be replaced by the data set number. See the sample output below for an example.
Sample Input
3cat tree tcraetecat tree catrteecat tree cttaree
Sample Output
Data set 1: yesData set 2: yesData set 3: no
Source
Pacific Northwest 2004
ACcode:dp wangyikun
PageWeb ContestsProblemsRanklistStatusStatisticsZipper Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 25 Accepted Submission(s) : 11Problem DescriptionGiven three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order.For example, consider forming "tcraete" from "cat" and "tree":String A: catString B: treeString C: tcraeteAs you can see, we can form the third string by alternating characters from the two strings. As a second example, consider forming "catrtee" from "cat" and "tree":String A: catString B: treeString C: catrteeFinally, notice that it is impossible to form "cttaree" from "cat" and "tree". InputThe first line of input contains a single positive integer from 1 through 1000. It represents the number of data sets to follow. The processing for each data set is identical. The data sets appear on the following lines, one data set per line. For each data set, the line of input consists of three strings, separated by a single space. All strings are composed of upper and lower case letters only. The length of the third string is always the sum of the lengths of the first two strings. The first two strings will have lengths between 1 and 200 characters, inclusive. OutputFor each data set, print: Data set n: yes if the third string can be formed from the first two, or Data set n: no if it cannot. Of course n should be replaced by the data set number. See the sample output below for an example. Sample Input3cat tree tcraetecat tree catrteecat tree cttaree Sample OutputData set 1: yesData set 2: yesData set 3: no SourcePacific Northwest 2004dfs zhangpeng:
#include <iostream>#include<cstdio>#include<string.h>using namespace std;#define maxn 10000bool flag;char a[maxn],b[maxn],c[maxn];int pos1,pos2,pos3;void dfs(int la,int lb,int lc ){ if(la+1==0&&lb+1==0) { flag=true; return; } if(!flag&&a[la]==c[lc]&&(la+1)) dfs(la-1,lb,lc-1); if(!flag&&b[lb]==c[lc]&&(lb+1)) dfs(la,lb-1,lc-1); return;}int main(){ int t,cns=0; cin>>t; for(int i=0; i<t; i++) { cin>>a>>b>>c; printf("Data set %d: ",++cns); flag=false; pos1=strlen(a); pos2=strlen(b); pos3=strlen(c); if(a[pos1-1]==c[pos3-1]||b[pos2-1]==c[pos3-1]) dfs(pos1-1,pos2-1,pos3-1); printf(flag?"yes\n":"no\n"); } return 0;}
0 0
- zipper dp与dfs poj4710
- Zipper(DFS,DP)
- POJ 2192 Zipper (DFS / DP)
- HDU 1501 Zipper(DP,DFS)
- HDU 1501 Zipper(DP,DFS)
- POJ2192 Zipper(DP||DFS)
- hdu1501 Zipper(dfs && dp)
- POJ 2192 Zipper [dfs+剪枝 || dp]
- hdu 1501 Zipper(dfs或dp)
- Zipper(dfs)
- HDU-1501 (POJ-2192) Zipper (DFS||DP)
- DFS poj 2192 zipper
- 【hdu】Zipper (dfs)
- hdu 1501 Zipper (DFS)
- HDU 1501 Zipper(DFS)
- hdu1501&&poj2192 Zipper(DFS)
- HDU 1501 Zipper 【DFS】
- hdu dfs Zipper
- 黑马程序员—OC基础—autorelease的使用
- android加载大图片
- 电子干涉--粒子还是波?
- maven 插件findbugs源代码的解析
- 初级数据持有化-沙盒
- zipper dp与dfs poj4710
- 继承hibernateDaoSupport之后通过注解方式注入SessionFactory
- 11用户手册
- Apache Mahout的KMeans算法测试
- Mysql 安装与配置
- 一张图看懂hash的核心思想(我只是从我的角度)
- LeetCode-Climbing Stairs
- 英文论文中“such as, for example, e.g., i.e., etc., et al. ”的用法分析
- Django1.8使用小结