Check in (11)

https://leetcode-cn.com/problems/palindrome-partitioning/

class Solution {
    
    
private:
    vector<vector<int>> f;//类似于KMP的失败函数
    vector<vector<string>> ret;//返回的答案
    vector<string> ans;//部分答案
    int n;//n代表的是一个n的值
public:
    void dfs(const string& s, int i){
    
    
        if(i==n){
    
    
            ret.push_back(ans);//当已经到达最底层的时候
            return;//结束战争
        }
        for(int j = i; j < n; ++j) {
    
    
            if (f[i][j]) {
    
    //若当前是回文串,则进行下一轮递归
                ans.push_back(s.substr(i, j - i + 1));//将此子串放入答案中,其中substr表示从
                //下标为i的地方开始,向后数j-i+1个数字的子串
                dfs(s, j + 1);//继续递归
                ans.pop_back();//回来之后把最上面的弹出去
            }
        }
    }
    vector<vector<string>> partition(string s) {
    
    
        n = s.size();
        f.assign(n, vector<int>(n, true));//初始化全部为true
        for (int i = n - 1; i >= 0; --i) {
    
    
            for (int j = i + 1; j < n; ++j) {
    
    
                f[i][j] = (s[i] == s[j]) && f[i + 1][j - 1];//动态规划,然后得到所有的dp值
            }
        }//复杂度为O(n^2)
        dfs(s, 0);//深度搜索
        return ret;//返回答案
    }
};

I laughed to death. I read a few people's blogs, but there is no suspicion of plagiarizing me, but some people have written so much, but not a single sentence is important. I may feel very fulfilled by the number of visitors. It is recommended to learn the data structure first before writing these things, it is ridiculous.

This topic is more about understanding KMP's thoughts, but I thought about it, but unfortunately, it is not detailed enough, and it still needs more in-depth thinking. I used to be able to think deeply about mathematics and have my own ideas. This is mathematics intuition. I hope I can make some significant results before I turn 26.

Just take a look and submit it, after all, there is really nothing to write about. Recently, let's talk about probability theory first. It seems that I am not the only one engaged in machine learning. Wu Enda's machine learning is really suitable for beginners. Yygq, should you focus on the simple and understandable? My head is a little dizzy, maybe it's troublesome. After pulling out the wisdom teeth, finish removing the thread.

I live again. Come to my senses, maybe you are someone else's blog from a certain big guy, forget it, don't pretend, don't mock others, be decent and right.

There is also a simple topic that is not written correctly. It is time to reflect on your own arrogance. So, now that a robotic cosmic machine that can solve all problems has been invented, when will a cosmic brain that can analyze all problems as a general solution come out?

Guess you like

Origin blog.csdn.net/weixin_47741017/article/details/114500664