显示代码纯文本
#include <cstdio>
#include <cstdlib>
using namespace std;
int n,maxhei=0,x[20],y[20];
void swap(int& a,int& b)
{
int temp;
temp=a;
a=b;
b=temp;
}
void qqsort(int l,int r)
{
int ll,rr,temp;
ll=l;
rr=r;
temp=x[rand()%(r-l+1)+l];
while (ll<=rr)
{
while (x[ll]>temp)
ll++;
while (temp>x[rr])
rr--;
if (ll<=rr)
{
swap(x[ll],x[rr]);
swap(y[ll],y[rr]);
ll++;
rr--;
}
}
if (l<rr)
qqsort(l,rr);
if (ll<r)
qqsort(ll,r);
}
void maketower(int num,int hei)
{
if (n-num+hei<maxhei)
return;
int i;
if (hei>maxhei)
maxhei=hei;
for (i=num+1;i<n;i++)
if (y[num]>y[i])
maketower(i,hei+1);
}
int main(void)
{
freopen("btwr.in","r",stdin);
freopen("btwr.out","w",stdout);
int i;
scanf("%d\n",&n);
for (i=0;i<n;i++)
scanf("%d %d\n",&x[i],&y[i]);
qqsort(0,n-1);
for (i=0;i<n;i++)
maketower(i,1);
printf("%d\n",maxhei);
fclose(stdin);
fclose(stdout);
return(0);
}