87. Scramble String ***
dbq,不会,理解不了题解。
class Solution {
public:
bool isScramble(string s1, string s2) {
if(s1.length()!=s2.length()) return false;
int n=s1.length();
vector<vector<vector<int>>> dp(n,vector<vector<int>>(n,vector<int>(n+1,0)));
for(int i=0;i<n;++i){
for(int j=0;j<n;++j)
dp[i][j][1]=s1[i]==s2[j];
}
for(int k=2;k<=n;++k){
for(int i=0;i+k<=n;++i){
for(int j=0;j+k<=n;++j){
for(int ck =1;ck<k;++ck){
dp[i][j][k] |=(
(dp[i][j][ck]&&dp[i+ck][j+ck][k-ck])||(dp[i][j+k-ck][ck]&&dp[i+ck][j][k-ck])
);
}
}
}
}
return dp[0][0][n];
}
};