ACM题目,速度的,浙大的题,谢谢啦

来源:百度知道 编辑:UC知道 时间:2024/06/05 07:26:53
Description】

A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).

Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.

【Input】

The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000

【Output】

Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.

【Sample Input】
7
1 7 3 5 9 4 8

【Sample Ou

#include <iostream>
#include <deque>
#include <cmath>
using namespace std;

int main()
{
int ai[1001];
int ff[1001];
int cas;
cin >> cas;
while(cas--)
{
int n;
cin >> n;
for(int i=0; i<n; i++)
{
cin >> ai[i];
ff[i] = 1;
}
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(ai[j] > ai[i] && ff[j] <= ff[i])
{
ff[j] = ff[i]+1;
}
}
}
int max=0;
for(int i=0; i<n; i++)
{
if(ff[i] > max)
max=ff[i];
}
cout << max << endl;
if(cas>0)
cout << endl;
}
return 0;
}

最长不降序列,简单的动态规划啊,下面这位仁兄的代码是对的,我就不啰嗦了

对!对!