H2230823078


私信TA

用户名:dotcpp0618148

访问量:899

签 名:

https://devcpp.gitee.io/

等  级
排  名 1112
经  验 3076
参赛次数 0
文章发表 9
年  龄 0
在职情况 学生
学  校 贺州学院
专  业

  自我简介:

https://royqh1979.gitee.io/redpandacpp/

#include <bits/stdc++.h>
using namespace std;

const int N = 30000 + 10;

int a[N], f1[N], f2[N];
int res1, res2;

int main() {

	int n = 1;
	while (cin >> a[n]) {
		n++;
	}
	for (int i = 1; i <= n - 1; i++) {
		f1[i] = 1, f2[i] = 1;
		for (int j = 1; j < i; j++) {
			if (a[i] <= a[j])//最长下降子序列
				f1[i] = max(f1[i], f1[j] + 1);

			if (a[i] > a[j])//最长上升子序列
				f2[i] = max(f2[i], f2[j] + 1);

		}
		res1 = max(res1, f1[i]);
		res2 = max(res2, f2[i]);
	}

	cout << res1 << endl << res2;
}

解题思路:

注意事项:

参考代码:

 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区