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)