标签:style blog http color os io for ar
大意:有n个盒子,前者只有xyz均大于后者,前者才可把后者装下
告诉你n个盒子的xyz求最少露在外面的盒子数
思路:最小路径覆盖 = n - 最大匹配
代码:
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 }
hdu4160Dolls【最小路径覆盖】,布布扣,bubuko.com
标签:style blog http color os io for ar
原文地址:http://www.cnblogs.com/zhanzhao/p/3908328.html