资源限制
时间限制:1.0s 内存限制:256.0MB
问题描述
你有个同学叫B君,他早听闻祖国河山秀丽,列了一张所有可能爬的山的高度表,因“人往高处走”的说法,所以他希望要爬的山按照表上的顺序,并且爬的每一座山都要比前一座高,爬的山数最多,请贵系的你帮他解决这个问题。(cin,cout很坑)
输入格式
输入第一行为num(1~1000)和maxHeight(1~8848),代表山的个数和最大高度
输入第二行有num个整数,代表表上每座山的高度height(1~maxHeight)
输出格式
输出只有一个数,为符合要求的最大爬山数
样例输入
10 10
8 6 8 5 9 5 2 7 3 6 3 4
样例输出
3
样例输入
10 20
8 19 9 10 3 3 15 3 10 6
样例输出
4
数据规模和约定
num(1~1000),maxHeight(1~8848),height(1~maxHeight),都是正整数
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,hei;
int ans = 0;
scanf("%d%d", &n, &hei);
int lst[n] = {0};//山的高度
int len[n] = {0};//保存递增序列的长度
for (int i = 0; i < n;i++)
scanf("%d", lst + i);
len[0] = 1;//第一个前面没有比他小的,所以是1
for (int i = 1; i < n;i++)
{
int Max = 0;//记录最长的递增序列
for (int j = 0; j < i;j++)
{
if (lst[i] >lst[j])//当前山比之前某一座山高
{
Max = max(len[j], Max);//取最长的递增序列
}
}
len[i] = Max + 1;
ans = max(len[i], ans);
}
cout << ans<<endl;
system("pause");
return 0;
}