参照了http://www.hankcs.com/program/cpp/poj-1065-wooden-sticks.html 代码写得很简洁
#include#include #include #include #include using namespace std;typedef long long ll;const int maxv=5e3+30;int t,n;typedef pair 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 () )=a[i].second; } cout< ())-dp-1<