标签:
1 10 1 2 2 4 5 8 6 10 7 9 3 1 5 8 12 10 9 7 2 2
5
/* Author: 2486 Memory: 240 KB Time: 0 MS Language: C++ Result: Accepted */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=1000+5; int T,n,dp[maxn]; struct rect { int x,y; } rs[maxn]; bool judge(rect &a,rect &b) { if((a.x<b.x&&a.y<b.y)||(a.y<b.x&&a.x<b.y))return true;//判断是否可以嵌入 return false; }; int dfs(int v) { int ans=1; if(dp[v]!=-1)return dp[v]; for(int i=0; i<n; i++) { if(judge(rs[i],rs[v])) {//满足条件向下递归 ans=max(dfs(i)+1,ans); } } return dp[v]=ans; } int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d%d",&rs[i].x,&rs[i].y); } memset(dp,-1,sizeof(dp)); int Max=0; for(int i=0; i<n; i++) { Max=max(dfs(i),Max); } printf("%d\n",Max); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qq_18661257/article/details/47133043