You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
// https://blog.csdn.net/u011815404/article/details/80542410
|
|
|
|
|
|
|
|
|
|
#define INF 0x3f3f3f3f
|
|
|
|
|
int a[101] = {0};
|
|
|
|
|
int f[101] = {0};
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
//输入+输出重定向
|
|
|
|
|
freopen("../1271.txt", "r", stdin);
|
|
|
|
|
|
|
|
|
|
//动态规则
|
|
|
|
|
int n;
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (int i = 1; i <= n; ++i) {
|
|
|
|
|
cin >> a[i];
|
|
|
|
|
}
|
|
|
|
|
//核心算法
|
|
|
|
|
//原理篇: https://blog.csdn.net/memory_cood/article/details/87936191
|
|
|
|
|
// 浅谈最长不下降子序列与最长上升子序列
|
|
|
|
|
// https://www.cnblogs.com/yuelian/p/8745807.html
|
|
|
|
|
for (int i = 1; i <= n; i++) { //遍历每一个元素
|
|
|
|
|
f[i] = 1; //以这个元素结尾的dp数组,默认值是1,即表示只有它自己一个
|
|
|
|
|
for (int j = 1; j < i; j++) { //从比它小的每一个数都过来计算一次
|
|
|
|
|
//找到比当前元素小的,并且以那个元素结尾的最长子序列长度+1比现在的大,就是猴子选大王,找最长的一条
|
|
|
|
|
if (a[j] < a[i] && f[j] + 1 > f[i]) {
|
|
|
|
|
f[i] = f[j] + 1; //修改猴王
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//初始值
|
|
|
|
|
int res = 0;
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
cout << f[i] << " ";
|
|
|
|
|
res = max(res, f[i]);
|
|
|
|
|
}
|
|
|
|
|
cout << endl;
|
|
|
|
|
cout << res << endl;
|
|
|
|
|
|
|
|
|
|
//关闭文件
|
|
|
|
|
fclose(stdin);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|