九度oj 1112 nyoj 79

nyoj

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

using namespace std;

const int MAXN  = 25;


int main()
{
    int h[MAXN], dp[MAXN];
    int n, res;
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i = 1; i <= n; ++i)
        {
            cin>>h[i];
            dp[i] = 1;
        }

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

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

九度oj

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

using namespace std;

const int MAXN = 10010;

int MAX(int a, int b)
{
    return a > b ? a : b;
}

int main()
{
    int n;
    int res;
    int h[MAXN], dp[MAXN];
    while(~scanf("%d", &n))
    {
        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[j] >= h[i])
                    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)