首页 > 代码库 > 最长不下降子序列--LIS

最长不下降子序列--LIS

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn = 100;

int main()
{
    int n;
    cin >> n;
    vector<int> datas;
    while (n--)
    {
        int tem;
        cin >> tem;
        datas.push_back(tem);
    }
    int dp[maxn];
    //fill(dp, dp + n+1, 1);
    int m = 0;
    for (int i = 0; i < datas.size(); ++i)
    {
        dp[i] = 1;
        for (int j = 0; j < i; ++j)
        {
            if (datas[i] > datas[j] && (dp[j] + 1 > dp[i]))
                dp[i] = dp[j] + 1;
            if (m < dp[i])m = dp[i];
        }
    }
    cout << m << endl;
    system("pause");
    return 0;
}

 

最长不下降子序列--LIS