标签:
3
1 5
6 2
3 4
2
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<vector> #define ll long long using namespace std; const int maxn = 2005; vector<int> g[maxn]; int n,a[maxn],b[maxn],topo[maxn],cnt; int f[maxn],ans; bool vis[maxn]; void dfs(int x){ vis[x] = true; for(int i = 0;i < g[x].size();i++){ if(!vis[g[x][i]]) dfs(g[x][i]); } topo[cnt--] = x; } void dp(int x){ if(!g[x].size()){ f[x] = 1; return; } for(int i = 0;i < g[x].size();i++){ if(!f[g[x][i]]) dp(g[x][i]); f[x] = max(f[x],f[g[x][i]] + 1); } ans = max(f[x],ans); } int main(){ cin>>n; for(int i = 1;i <= n;i++){ scanf("%d%d",&a[i],&b[i]); if(a[i] < b[i]) swap(a[i],b[i]); } for(int i = 1;i <= n;i++){ for(int j = i+1;j <= n;j++){ if(a[i] > a[j] && b[i] > b[j]) g[i].push_back(j); else if(a[j] > a[i] && b[j] > b[i]) g[j].push_back(i); } } cnt = n; for(int i = 1;i <= n;i++){ if(!vis[i]) dfs(i); } for(int i = 1;i <= n;i++){ if(!f[topo[i]]) dp(topo[i]); } cout<<ans; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5689446.html