求助,求不上升子序列为啥第一个300出来的是p=0呢
查看原帖
求助,求不上升子序列为啥第一个300出来的是p=0呢
759274
Stevehim楼主2022/11/13 22:02
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#define maxn 10000010
using namespace std;
int a[maxn];

int b[maxn] = {0};
int temp;
int i = 1; //从1开始计数
int last = 1;
void sss() {
	for (int j = 1; j <= last; j++) {
		cout << b[j] << ' ';
	}
	cout << endl;
}
int main() {
	int n;
	cin >> n;

	while (n--) {
		scanf("%d", &temp);
		a[i++] = temp;
	}
	cout << 7 << endl;
	cout << i << endl;
//	while (scanf("%d", &temp) != EOF) {
//		a[i++] = temp;
//	}
	b[last] = a[1];
	for (int j = 2; j < i; j++) {
		if (b[last] >= a[j]) {
			last++;
			b[last] = a[j];
			cout << 1 << endl;
		} else {
			cout << a[j] << endl;
			sss();
			int p = upper_bound(b + 1, b + last + 1, a[j]) - b;
			cout << "p=" << p << ' ' << *upper_bound(b + 1, b + last + 1, a[j]) <<  endl;
			b[p] = a[j];
		}
	}
	cout << last << endl;
	return 0;
}

2022/11/13 22:02
加载中...