最长不降序子序列
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static int n = sc.nextInt();
static int a[] = new int[n];
static int b[] = new int[100];
static int manxlen = 0;
static void dfs(int now,int pos,int count,int a[]){
if(now >= n){
if(count > manxlen){
manxlen = count;
return;
}
}
for(int i = now;i < n;i++){
if(pos == 0 || b[pos - 1] <= a[i]){
b[pos] = a[i];
count++;
dfs(i+1,pos+1,count,a);
count--;
}
}
}
public static void main(String[] args) throws IOException {
for(int i = 0;i <n;i++){
a[i] = sc.nextInt();
}
if(a.length == 0){
System.out.println(0);
}else{
manxlen = 0;
dfs(0,0,0,a);
System.out.println(manxlen);
}
}
}
查看3道真题和解析
三奇智元机器人科技有限公司公司福利 65人发布