前言
思路
看上去是含捆绑关系的 L I S LIS LIS,但是其实只要对一个关键排序,
然后另一个跑一遍 L I S LIS LIS即可
至于这题比较难的是输出路径
我们可以使用 p r e pre pre数组进行转移,每当其转移的时候 我们更改即可
Mycode
const int N = 5e3+10;
struct node{
int w,h,id;
};
vector<node> a;
bool cmp(node t1,node t2){
return t1.w < t2.w;
}
int f[N],pre[N],hh;
int n,W,H;
int ans;
void print(int hh){
if(hh == -1)
return;
print(pre[hh]);
cout<<a[hh].id<<" ";
}
void solve()
{
cin>>n>>W>>H;
for(int i=1;i<=n;i++){
int w,h;cin>>w>>h;
if(w > W && h> H){
a.pb({w,h,i});
}
}
if(a.empty()){
cout<<0<<endl;
return;
}
sort(all(a),cmp);
for(int i = 0; i< a.size() ;i++){
f[i] = 1;
pre[i] = -1;
}
int n = a.size();
ans = 1;
for(int i = 1 ;i < n ;i++ ){
for(int j = 0;j<i;j++){
if(a[j].w < a[i].w)
if(a[j].h < a[i].h)
if(f[j]+1 > f[i]){
f[i] = f[j]+1;
pre[i] = j ;
}
}
if(ans < f[i]){
ans = f[i];
hh = i;
}
}
cout<<ans<<endl;
print(hh);
}