为什么我认为这是最长上升子序列呀
查看原帖
为什么我认为这是最长上升子序列呀
648005
golemon楼主2022/9/15 23:56

我认为这一题与P1020 [NOIP1999 普及组] 导弹拦截 的第二问相似,求LIS,代码如下,但是为什么错误呀。

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stdio.h>
#include <algorithm>
using namespace std;

#define rep(i,x,n) for(int i = x; i <= n; i++)

typedef long long LL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const int N = 10021;
struct LR {
	int l,r;
	bool operator< (const LR& k) const {
		if(l == k.l) return r>k.r;
		return l>k.l;
	}
}lr[N];
int dp[N];
void test();
int main()
{
	int n; cin>>n;
	rep(i,1,n) cin>>lr[i].l>>lr[i].r;
	sort(lr+1,lr+n+1);
	rep(i,1,n) {
		dp[i] = 1;
		rep(j,1,i-1) {
			if(lr[i].l > lr[j].l && lr[j].r < lr[i].r) dp[i] = max(dp[i], dp[j]+1);
			//if(lr[i].r > lr[j].r) dp[i] = max(dp[i], dp[j]+1);
		}
	}
	cout<<*max_element(dp+1,dp+n+1);
	return 0;
}

void test() {
	#define mytest
	#ifdef mytest
	freopen("ANSWER.txt", "w",stdout);
	#endif
}
2022/9/15 23:56
加载中...