Acwing 895. rise longest sequence

Given a number of columns N of the length of the longest find the value of a strictly monotonic increasing sequence length is.

Input Format

The first row contains an integer N.

The second line contains N integers representing the complete sequence.

Output Format

Output an integer, represents the maximum length.

data range

1 N 1000 1≤N≤1000,
- 10 9 number columns in manner number 10 9 -109≤ sequence mid manner several ≤109

Sample input:

7
3 1 2 1 8 5 6

Sample output:

4


思路:
The dynamic equation of the transfer, after each last a [i] at the end of the maximum value monotonically increasing sequence is taken to loop through the last maximum value is performed for each class Max 
time complexity: O (n ^ 2)
 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 const int N = 1e5;
 5 int n;
 6 int a[N];
 7 int f[N];
 8 int main(){
 9   scanf("%d",&n);
10   for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
11   for(int i = 1;i <= n;i++){
12     f[i] = 1;
13     for(int j = 1;j < i;j++)
      //动态转移方程
14 if(a[i] > a[j]) f[i] = max(f[i],f[j] + 1); 15 } 16 17 int res = 0; 18 for(int i = 1;i <= n;i++) res = max(res,f[i]); 19 printf("%d",res); 20 } 21

 

Guess you like

Origin www.cnblogs.com/luyuan-chen/p/11601332.html