Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4160
There are n cuboid-shaped dolls, when the length and width of the height is less than the other time can be put in, each inside a maximum of one, ask the best set method, the last number of dolls can be left;
With the N-Max match on the line;
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#defineN 550intN, Vis[n], used[n], maps[n][n];structnode{intx, Y, Z, DP;} A[n];intCMP (node p, node Q) {if(p.x!=q.x)returnP.x <q.x; Else if(p.y!=q.y)returnP.y <q.y; returnP.z <q.z;}BOOLFind (intu) { for(intI=1; i<=n; i++) { if(!vis[i] &&Maps[u][i]) {Vis[i]=1; if(!used[i] | |Find (Used[i])) {Used[i]=u; return true; } } } return false;}intMain () { while(SCANF ("%d", &N) {memset (A,0,sizeof(a)); memset (Used,0,sizeof(used)); memset (Maps,0,sizeof(maps)); for(intI=1; i<=n; i++) {scanf ("%d%d%d", &a[i].x, &A[I].Y, &a[i].z); } sort (A+1, a+n+1, CMP); for(intI=1; i<=n; i++) { for(intj=1; j<i; J + +) { if(a[j].x<a[i].x && a[j].y<a[i].y&&a[j].z<a[i].z) {Maps[j][i]=1; } } } intans=0; for(intI=1; i<=n; i++) {memset (Vis,0,sizeof(VIS)); if(Find (i)) ans++; } printf ("%d\n", N-ans); } return 0;}
View Code
Dolls---hdu4160 (maximum match)