POJ 1065 学习写法

参照了http://www.hankcs.com/program/cpp/poj-1065-wooden-sticks.html 代码写得很简洁

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<functional>
using namespace std;
typedef long long ll;
const int maxv=5e3+30;
int t,n;
typedef pair<int,int> stick;
stick a[maxv];
int dp[maxv];
int main(){
    freopen("in","r",stdin);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++) scanf("%d%d",&a[i].first,&a[i].second);
        memset(dp,-1,sizeof dp);
        sort(a+1,a+n+1);
        for(int i=1;i<=n;i++){
            *lower_bound(dp+1,dp+n+1,a[i].second, greater<int>() )=a[i].second;
        }
        cout<<lower_bound(dp+1,dp+n+1,-1,greater<int>())-dp-1<<endl;
    }
    return 0;
}

 

posted @ 2015-04-29 17:43  PlusSeven  阅读(144)  评论(0编辑  收藏  举报