Pyramid I

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/iov3Rain/article/details/90243314

Title Description

Pyramid is a well-known game in which a person should stand on another's shoulders. At the same time we should let the following people a bit higher than the above people. Known to participate in the game each person's height, write the code to calculate by people choose to participate in the game, we can stack up to the number of individuals. Note that the people are to have the means to participate in the game of human order and the order of the original sequence should be consistent.

Given a height int array everyone men, followed by representatives of the. At the same time given the total number n, go back up to the number stack. N less than or equal to ensure 500.

Test sample:

[1,6,2,5,3,4],6

Returns: 4

 

 

Rise longest subsequence problem

 

class Stack {
public:
    int getHeight(vector<int> men, int n) {
        // write code here
        if(n <= 0)
            return 0;
        vector<int> dp(n, 1);
        int ans = 1;
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < i; ++j)
            {
                if(men[i] > men[j])
                {
                    dp[i] = max(dp[i], dp[j] + 1);
                }
            }
            ans = max(dp[i], ans);
        }
        return ans;
    }
};

 

 

Guess you like

Origin blog.csdn.net/iov3Rain/article/details/90243314