题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=79

题意即求最长单调递减子序列

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 22

int h[N];
int d[N];

int main()
{
    freopen("d:\\in.txt", "r", stdin);
    int t, n;
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=0; i<n; i++)
            cin>>h[i];
        int ans = 0;
        for(int i=n-1; i>=0; i--){
            d[i] = 1;
            for(int j=i+1; j<n; j++){
                if(h[j] < h[i])
                    d[i] = max(d[i], d[j]+1);
            }
            ans = max(ans, d[i]);
        }
        cout<<ans<<endl;
    }
}
 posted on 2015-04-13 17:14  平和之心  阅读(174)  评论(0编辑  收藏  举报