poj1936

来源:互联网 发布:淘宝返利网哪个好用 编辑:程序博客网 时间:2024/05/16 17:31
All in All
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 25104 Accepted: 10100

Description

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string. 

Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s. 

Input

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace.The length of s and t will no more than 100000.

Output

For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

Sample Input

sequence subsequenceperson compressionVERDI vivaVittorioEmanueleReDiItaliacaseDoesMatter CaseDoesMatter

Sample Output

YesNoYesNo

Source

Ulm Local 2002

纯粹的LCS 只不过用滚动数组节省空间。
#include <iostream>#include <cstdio>#include <cstring>#define MAX 100001using namespace std;int main(){    char s1[MAX],s2[MAX];    while(~scanf("%s %s",s1,s2)){        int len1 = strlen(s1);        int len2 = strlen(s2);        int cost[2][MAX];        for(int i=0;i<MAX;i++)        {            cost[0][i]=0;            cost[1][i]=0;        }        int m = -1;        for(int i=1;i<=len1;i++)            for(int j=1;j<=len2;j++)            {                if(s1[i-1]==s2[j-1])                {                    cost[i%2][j] = cost[(i-1)%2][j-1]+1;                    m = max(m,cost[i%2][j]);                }                else                    cost[i%2][j] = max(cost[(i-1)%2][j],cost[i%2][j-1]);            }        if(m==len1)            printf("Yes\n");        else            printf("No\n");    }    return 0;}


原创粉丝点击