标签:
#include<cstdio> #include<algorithm> int n; int f[1010],ans=0; int es[1000010],enx[1000010],e0[2010],ed[2010],nx[2010],now=1,ep=2; void maxs(int&a,int b){if(a<b)a=b;} struct pos{int x,y,z;}ps[1010]; bool cmp(pos a,pos b){return a.x<b.x;} bool operator<(pos a,pos b){return a.x<b.x&&a.y<b.y&&a.z<b.z;}; void adde(int a,int b){ es[ep]=b;enx[ep]=e0[a];e0[a]=ep++; es[ep]=a;enx[ep]=e0[b];e0[b]=ep++; } bool dfs(int w){ ed[w]=now; if(nx[w]&&ed[nx[w]]!=now)return dfs(nx[w]); for(int i=e0[w];i;i=enx[i]){ int u=es[i]; if(ed[u]==now)continue; if(!nx[u]||dfs(u)){ nx[w]=u;nx[u]=w; return 1; } } return 0; } int main(){ scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d%d%d",&ps[i].x,&ps[i].y,&ps[i].z); std::sort(ps,ps+n,cmp); for(int i=0;i<n;i++){ f[i]=1; for(int j=0;j<i;j++)if(ps[j]<ps[i]){ maxs(f[i],f[j]+1); adde(i,j+n); } maxs(ans,f[i]); } printf("%d\n",ans); ans=n; for(int i=1;i<=n;i++,now++)if(!nx[i])ans-=dfs(i); printf("%d\n",ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/ccz181078/p/5719341.html