蒟蒻最长上升子序列求条!玄关
查看原帖
蒟蒻最长上升子序列求条!玄关
902351
Little_x_starTYJ楼主2024/10/9 15:23

首先 Sub 1 全过,然后 Sub 2 WA了。

#include <bits/stdc++.h>
using namespace std;
int dp[5010], a[5010], ans;
int main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++) {
		dp[i] = 1;
		for (int j = 1; j < i; j++) {
			if (a[i] >= a[j])
				dp[i] = max(dp[i], dp[j] + 1);
		}
		ans = max(ans, dp[i]);
	}
	cout << ans;
	return 0;
}
2024/10/9 15:23
加载中...