Result: Accepted
Time: 6ms
Memory: 1764kB
#include<cstdio>
#include <algorithm>
#include <iostream>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=1005;
struct node
{
int h,w;
}a[maxn];
int main()
{
int n,sum=1,hmin[maxn],wmin[maxn],flag=1;
memset(hmin,0,sizeof(hmin));
memset(wmin,0,sizeof(wmin));
scanf("%d",&n);
scanf("%d %d",&a[1].h,&a[1].w);
hmin[1]=a[1].h;
wmin[1]=a[1].w;
for(int i=2;i<=n;i++)
{
flag=1;
scanf("%d %d",&a[i].h,&a[i].w);
for(int j=1;j<=sum;j++)
{
if((a[i].h<=hmin[j]&&a[i].w<=wmin[j])||(a[i].w<=hmin[j]&&a[i].h<=wmin[j]))
{
flag=1;
hmin[j]=a[i].h;
wmin[j]=a[i].w;
break;
}
else flag=0;
}
if(flag==0)
{
sum++;
hmin[sum]=a[i].h;
wmin[sum]=a[i].w;
}
}
printf("%d\n",sum);
// system("pause");
}