HDU 4160 — Dolls 最小路径覆盖

来源:互联网 发布:淘宝商家可以看到买家 编辑:程序博客网 时间:2024/06/12 00:09

原题:http://acm.hdu.edu.cn/showproblem.php?pid=4160

题意:

有n个箱子,下面n行给出每个箱子的长、宽、高;

大箱子可以嵌套小箱子(要求长宽高均小于外面的箱子,且长宽高一一对应,即长对应长);

问露在外面箱子有几个;


思路:

1的体积小于2,2的体积小于3,那么3套2、2套1,就只有一个箱子3露在外面,可以想到是最小路径覆盖;

最小路径覆盖 = 顶点数-最大匹配数;


#include<stdio.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;const int maxn = 550;int n;bool used[maxn];int match[maxn];vector<int>G[maxn];struct node{    int a, b, c;}box[maxn];bool find(int x){    for(int i = 0;i<G[x].size();i++)    {        int t = G[x][i];        if(!used[t])        {            used[t] = true;            if(match[t] == 0 || find(match[t]))            {                match[t] = x;                return true;            }        }    }    return false;}int main(){    while(scanf("%d", &n) && n)    {        memset(match, 0, sizeof match);        for(int i = 1;i<=n;i++)            scanf("%d%d%d", &box[i].a, &box[i].b, &box[i].c);        for(int i = 1;i<=n;i++)        {            G[i].clear();            for(int j = 1;j<=n;j++)            {                if(box[i].a<box[j].a && box[i].b<box[j].b && box[i].c<box[j].c)                G[i].push_back(j);            }        }        int sum = 0;        for(int i = 1;i<=n;i++)        {            memset(used, false, sizeof used);            if(find(i))            sum++;        }        printf("%d\n", n-sum);    }    return 0;}

,

0 0
原创粉丝点击