30pts求调
查看原帖
30pts求调
1208635
caochenkai楼主2024/9/30 13:48

使用dp+单调栈,AC#1#2#3,其他全WA(玄二关

#include<bits/stdc++.h>
using namespace std;
struct node {
	int a,b;
} x[100005];
int n,dp[100005],st[100005],top=1;
bool cmp(node i,node j) {
	return i.a<j.a;
}
int main() {
	memset(st,0x3f3f3f3f,sizeof(st));
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>x[i].a;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>x[i].b;
	} 
	sort(x+1,x+n+1,cmp);
	for(int i=1; i<=n; i++) {
		int bh=upper_bound(st+1,st+top+1,x[i].b)-st;
		if(bh==top)top++;
		st[bh]=x[i].b;
		dp[i]=bh;
	}
	cout<<top-1;
}
2024/9/30 13:48
加载中...