按照长度从长到短排好序,若长度相等,则以重量排序,再求重量的最长递增序列。类似于hdu的FatMouse's Speed 。
#include<iostream>
#include<algorithm>
using namespace std;
struct sticks{
int l;
int w;
}xx[5005];
int f[5005];
int cmp(sticks a,sticks b)
{
if(a.l==b.l)
return a.w<b.w;
else
return a.l<b.l;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>xx[i].l>>xx[i].w;
f[i]=0;
}
sort(xx+1,xx+n+1,cmp);
int sum=0;
int temp;
for(int i=1;i<=n;i++)
{
if(f[i]) continue;
temp=xx[i].w;
for(int j=i+1;j<=n;j++)
{
if(f[j]==0&&temp<=xx[j].w)
{
f[j]=1;
temp=xx[j].w;
}
}
sum++;
}
cout<<sum<<endl;
}
return 0;
}
hdu 1051 Wooden Sticks
最新推荐文章于 2019-11-18 13:32:49 发布
