hdu 1257

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXN = 100010;
int MAX(int a, int b)
{
    return a > b ? a : b;
}

int main()
{
    int n, res;
    int h[MAXN], dp[MAXN];
    while(~scanf("%d", &n))
    {
        memset(h, 0, sizeof(h));
        memset(dp, 0, sizeof(dp));
        for(int i = 1; i <=n; ++i)
        {
            cin>>h[i];
            dp[i] = 1;
        }

        for(int i = 1; i <= n; ++i)
        {
            for(int j = 1; j < i; ++j)
                if(h[i] > h[j])
                    dp[i] = MAX(dp[i], dp[j]+1);
        }

        res = 1;

        for(int i = 1; i <= n; ++i)
            if(dp[i] > res)
                res = dp[i];
        cout<<res<<endl;
    }
    return 0;
}

你可能感兴趣的:(dp)