大意:有n个盒子,前者只有xyz均大于后者,前者才可把后者装下
告诉你n个盒子的xyz求最少露在外面的盒子数
思路:最小路径覆盖 = n - 最大匹配
代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <vector> 5 using namespace std; 6 7 const int maxn = 505; 8 struct Node { 9 int x, y, z; 10 }node[maxn]; 11 12 int n; 13 int vis[maxn]; 14 int Link[maxn]; 15 vector<int> G[maxn]; 16 bool Find(int u) { 17 for(int i = 0; i < G[u].size(); i++) { 18 int v = G[u][i]; 19 if(!vis[v]) { 20 vis[v] = 1; 21 if(Link[v] == -1 || Find(Link[v])) { 22 Link[v] = u; 23 return true; 24 } 25 } 26 } 27 return false; 28 } 29 30 int solve() { 31 memset(Link, -1, sizeof(Link)); 32 int cnt = 0; 33 for(int i = 1; i <= n; i++) { 34 if(G[i].size()) { 35 memset(vis, 0, sizeof(vis)); 36 if(Find(i)) cnt++; 37 } 38 } 39 return cnt; 40 } 41 42 bool check(int i, int j) { 43 if(node[i].x > node[j].x && node[i].y > node[j].y && node[i].z > node[j].z) return true; 44 return false; 45 } 46 47 int main() { 48 while(scanf("%d",&n) && n) { 49 for(int i = 1; i <= n; i++) { 50 G[i].clear(); 51 scanf("%d %d %d",&node[i].x, &node[i].y, &node[i].z); 52 } 53 for(int i = 1; i <= n; i++) { 54 for(int j = 1; j <= n; j++) { 55 if(i == j) continue; 56 if(check(i, j)) G[i].push_back(j); 57 } 58 } 59 printf("%d\n", n - solve()); 60 } 61 return 0; 62 }