January 25 summary

Recently, the epidemic looks very not optimistic, hoping Wuhan compatriots can quite make it strong, so many people do not leave us in 2020. I strongly believe that one day, this will be the last day of chaos! Seize opportunities, meet challenges, willing Jun Shining sight, the sky one day break! Wuhan Come on! ! !

A. For the first strategy Summary - live in order to live well clear

1. How to quickly enter the state

Away from the phone, sing

2. do question should be how do

 

3. how to pick topics

 

4. day you learn how to measure good or bad

Quantitative, rules, given time

5. What exactly needs

 

6. how to read the code, not to be confused

 

Classification break, there is a type of variable, storage, and operations. Understanding storage variable is the first step in understanding the problem of

B.Leetcode132 

132. Palindrome Partitioning II
Hard

Given a string s, partition s such that every substring of the partition is a palindrome.

Return the minimum cuts needed for a palindrome partitioning of s.

Example:

Input: "aab"
Output: 1
Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
// appreciated that the storage variable is the meaning of the first step in understanding the problem 
class Solution {
 public :
     int MinCut ( String S) {
         // special Analyzing important 
        IF (s.empty ()) return  0 ;
         int n-= s.size ();
         // if p is stored in the two-dimensional array of j to i is a palindromic sequence interval, bool type, to true / to false 
        Vector <Vector < BOOL >> p (n-, Vector < BOOL > (n-));
         / / int type dp is the number of knives to cut the current state 
        Vector < int > dp (n-);
         for ( int I = 0 ; I <n-; ++I) {
             // Default is no palindromic sequence, each character is self-contained, it is the largest case where 
            DP [I] = I;
             // traversing, j. . I 
            for ( int J = 0 ; J <= I; ++ J) {
                 // If the same element and the two immediately adjacent elements, or the elements between which originally can determine the current range palindromic palindromic 
                IF (S [I] == S [J] && (I - J < 2 || P [+ J . 1 ] [I - . 1 ])) { 
                    P [J] [I] = to true ;
                     // has judged that it is a palindrome It can be cut, if the current is calculated from the beginning the knife is 0, or minimum values of +1 and left to see node taken as the right node of the current node 
                    DP [I] = (J == 0 )? 0: Min (DP [I], DP [J - . 1 ] + . 1 ); 
                } 
            } 
        } 
        // n-points but is the subscript n-1 so that the last digit is the need to subject the knife to cut 
        return DP [n-- . 1 ]; 
    } 
};

 



// store a variable understood meaning of the first step in understanding the problem class Solution {public: int minCut (string s) {// special Analyzing important if (s.empty ()) return 0; int n = s.size (); // if p is stored in the two-dimensional array of j to i is a palindromic sequence interval, bool type, true / false vector <vector <bool >> p (n, vector <bool> (n)); / / int type dp is the current state of the knife to cut the number of vector <int> dp (n); for (int i = 0; i <n; ++ i) {// default is no palindromic sequence, since each character into one, it is the largest case where dp [i] = i; // traversing, j. . i for (int j = 0; j <= i; ++ j) {// If the same element and the two immediately adjacent elements, or the elements between which originally can determine the current range palindromic palindromic if (s [i] == s [j] && (i - j <2 || p [j + 1] [i - 1])) {p [j] [i] = true; // palindrome has determined that it is can be cut, if the current is calculated from the beginning the knife is 0, or minimum values ​​of +1 and left to see node taken as the right node of the current node dp [i] = (j == 0) 0:? min (dp [i], dp [j - 1] + 1);
1. How to quickly enter the state
2. do question how to do
3. how to pick topics
4. one day learn how to measure their good
5. Party A father needs what
6. how to read the code, not to be confused
classified break, variable It is typed, stored operation. Understanding storage variable is the first step in understanding the problem of

Guess you like

Origin www.cnblogs.com/Marigolci/p/12233524.html