题目链接: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; } }
时间: 2024-10-03 22:41:58