poj 1065(贪心)

据说是贪心加dp,其实就是贪心

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=5000+10;
typedef pair<int,int> pp;
pp a[maxn];
int t,n;
int use[maxn];
bool cmp1(pp x,pp y)
{
    return (x.first<=y.first)||(x.first==y.first&&x.second<=y.second);
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        memset(use,0,sizeof(use));
        scanf("%d",&n);
        for(int i=0; i<n; i++)
            scanf("%d%d",&a[i].first,&a[i].second);
        sort(a,a+n,cmp1);
        int ans=0;
        for(int i=0; i<n; i++)
        {
            int ff=a[i].second;
            if(!use[i])//一个新的上升子序列开始
            {
                for(int j=i+1; j<n; j++)
                    if(a[j].second>=ff&&!use[j])
                    {
                        use[j]=1;
                        ff=a[j].second;//更新最大值,也就是这个上升子序列的最后一个元素,不断更新
                    }
                ans++;
            }

        }
        printf("%d\n",ans);
    }
    return 0;
}

 

posted on 2017-05-25 21:44  发牌员  阅读(126)  评论(0编辑  收藏  举报

导航