求最长不下降序列
状态转移方程:if(ai>aj) fi = max(fi, fj+1)
#include <iostream>
#include <cstdio>
using namespace std;
//Mystery_Sky
//
#define M 1000
int f[M], a[M], n, t=0;
int ans, ans_num, next[M], ans_xu[M];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]), f[i] = 1;
for(int i = 2; i <= n; i++)
for(int j = 1; j < i; j++)
if(a[i] >= a[j]) { //坑点
if(f[j] + 1 > f[i]) {
f[i] = f[j] + 1;
next[i] = j;
}
}
for(int i = 1; i <= n; i++) {
if(f[i] > ans) {
ans = f[i];
ans_num = i;
}
}
printf("max=%d
", ans);
while(ans_num) {
ans_xu[++t] = a[ans_num];
ans_num = next[ans_num];
}
for(int i = t; i >= 1; i--) printf("%d ", ans_xu[i]);
return 0;
}