交织的字符串
#include<string>
#include<vector>
#include<deque>
using namespace std;
class Solution {
public:
bool isInterleave(string s1, string s2, string s3) {
int s1Length = s1.length();
int s2Length = s2.length();
int s3Length = s3.length();
if (s1Length + s2Length != s3Length)
return false;
vector<vector<int>> dp(s1Length + 1, vector<int>(s2Length + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= s1Length; ++i)
{
dp[i][0] = dp[i - 1][0] && (s1[i - 1] == s3[i - 1]);
}
for (int j = 1; j <= s2Length; ++j)
{
dp[0][j] = dp[0][j - 1] && (s2[j - 1] == s3[j - 1]);
}
for (int i = 1; i <= s1Length; ++i)
{
for (int j = 1; j <= s2Length; ++j)
{
dp[i][j] = (dp[i - 1][j] && (s1[i - 1] == s3[i + j - 1]))
|| (dp[i][j - 1] && (s2[j - 1] == s3[i + j - 1]));
}
}
return dp[s1Length][s2Length];
}
};