HDU 5707 Combine String (Dp,lcs variant)

Source: Internet
Author: User
Tags first string

Test instructions: Given three strings, ask you if the third one is not made up of the first and the second.

Analysis: At that time the game did not make Ah ... Always WA, is not judging the length, the first and the second and is not the same as the third one, this forget ...

We use D[I][J] to indicate that the first string matches to I, the second match to the J, and then just judge if it can be obtained from the previous one. This is mostly d[i][j]==1, which means that it can be successfully matched

D[i][j]==0 means the match is not successful, so the rest is simple.

The code is as follows:

#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map>using namespace std; typedef long Long Ll;typedef pair<int, int> p;const int INF = 0x3f3f3f3 F;const Double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = + 5;const int dr[] = {0, 0,-1, 1};con  St int dc[] = {-1, 1, 0, 0};//int N, M;char S[MAXN], T[MAXN], ss[maxn];int d[maxn][maxn];int Main () {//int t;    Cin >> T;        while (scanf ("%s", s+1) = = 1) {scanf ("%s", t+1);        scanf ("%s", ss+1);        memset (d, 0, sizeof (d));        int n = strlen (s+1);        int m = strlen (t+1);        int ans = 0;            if (n+m! = strlen (ss+1)) {printf ("no\n");        Continue        } d[0][0] = 1;                for (int i = 0, I <= N; ++i) {for (int j = 0; j <= m; ++j) {if (ss[i+j] = = S[i] && i) d[i][j] |= d[i-1][j];            if (ss[i+j] = = T[j] && j) d[i][j] |= d[i][j-1]; }} printf ("%s\n", D[n][m]?    "Yes": "No"); } return 0;}

HDU 5707 Combine String (Dp,lcs variant)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.