您的位置:首页 > 其它

hdoj 1051 Wooden Sticks(上升子序列个数问题)

2012-10-25 16:46 267 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1051
View Code

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef struct node
{
int x,y;
int flag;
}sut;
bool cmp(sut a,sut b)
{
if(a.x!=b.x)
return a.x>=b.x;
else
return a.y>=b.y;
}
int main()
{
int t,n,i,j,num;
sut st[5010],hd;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&st[i].x,&st[i].y);
st[i].flag=0;
}
sort(st,st+n,cmp);
num=0;
for(i=0;i<n;i++)
{
if(st[i].flag==0)
{
st[i].flag=1;
num++;
hd=st[i];
for(j=i+1;j<n;j++)
{
if(st[j].flag==0&&hd.y>=st[j].y)
{
st[j].flag=1;
hd=st[j];
}
}
}
}
printf("%d\n",num);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: