LIS 的 限制条件变为了两个,然后记录路径倒序输出即可,注意答案为1的情况;
AC代码
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=1e5+10;
struct point{
int w;
int h;
int id;
}pt[maxn];
int pre[maxn];
int dp[maxn];
bool cmp(point a,point b)
{
if (a.w==b.w)
return a.h<b.h;
else
return a.w<b.w;
}
void print(int j)
{
if (pre[j]==-1)
{
printf("%d",j);
return;
}
print(pre[j]);
printf(" %d",j);
}
int main()
{
int n,wi,he,k=1,po,ww,hh,poo;
int flag=0,maxx=0;
cin>>n>>wi>>he;
for (int i=1;i<=n;i++)
{
cin>>ww>>hh;
if (ww>wi&&hh>he)
{
pt[k].w=ww;
pt[k].h=hh;
pt[k++].id=i;
poo=i;
flag=1;
}
}
sort (pt+1,pt+k,cmp);
if (!flag)
cout<<"0"<<endl;
else
{
pre[0]=-1;
for (int i=1;i<=n;i++)
{
dp[i]=1;
pre[i]=-1;
}
for (int i=1;i<=k;i++)
for (int j=1;j<i;j++)
{
if (pt[i].w>pt[j].w&&pt[i].h>pt[j].h)
{
if (dp[j]+1>dp[i])
{
dp[i]=dp[j]+1;
pre[pt[i].id]=pt[j].id;
if (dp[i]>maxx)
{
maxx=dp[i];
po=pt[i].id;
}
}
}
}
if (maxx==0)
{
printf("1\n");
printf("%d\n",poo);
}
else
{
printf("%d\n",maxx);
print(po);
printf("\n");
}
}
return 0;
}