其他分享
首页 > 其他分享> > [AcWing 1017] 怪盗基德的滑翔翼

[AcWing 1017] 怪盗基德的滑翔翼

作者:互联网

image
image


点击查看代码
#include<iostream>

using namespace std;

const int N = 110;

int k, n;
int a[N], f[N];

int main()
{
	cin >> k;
	while (k --) {
		cin >> n;
		for (int i = 1; i <= n; i ++)	cin >> a[i];
		int res = 0;
		for (int i = 1; i <= n; i ++) {
			f[i] = 1;
			for (int j = 1; j < i; j ++) {
				if (a[i] > a[j])
					f[i] = max(f[i], f[j] + 1);
			}
			res = max(res, f[i]);
		}
		for (int i = n; i >= 1; i --) {
			f[i] = 1;
			for (int j = n; j > i; j --) {
				if (a[i] > a[j])
					f[i] = max(f[i], f[j] + 1);
			}
			res = max(res, f[i]);
		}
		cout << res << endl;
	}
	return 0;
}

  1. 分别正向和反向求解最长上升子序列,取两种情况的最大值

标签:int,max,滑翔翼,怪盗,cin,--,res,基德
来源: https://www.cnblogs.com/wKingYu/p/16383725.html