求助,用动态规划写为什么只有40分
查看原帖
求助,用动态规划写为什么只有40分
1258100
wanttoac楼主2024/1/11 18:21
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define maxn 1000000
int d[maxn] = { 1 };
int main() {
	vector<int>nums;
	int num, n;
	cin >> n;
	int maxx = 0;
	for (int i = 0; i < n; i++) {
		cin >> num;
		nums.push_back(num);
	}
	for (int i = 1; i < n; i++) {
		for (int q = 0; q < i; q++) {
			if (nums[q] < nums[i]) {
				d[i] = max(d[i], d[q] + 1);
			}
		}
		if (d[i] > maxx)maxx = d[i];
	}
	cout << maxx;
	return 0;
}
2024/1/11 18:21
加载中...