题意:长方块嵌套,不能旋转,严格递增,建立二分图
求最大匹配
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<cstdlib>
#define lson (rt<<1),L,M
#define rson (rt<<1|1),M+1,R
#define M ((L+R)>>1)
#define cl(a,b) memset(a,b,sizeof(a));
#define LL long long
#define P pair<int,int>
#define X first
#define Y second
#define pb push_back
#define fread(zcc) freopen(zcc,"r",stdin)
#define fwrite(zcc) freopen(zcc,"w",stdout)
using namespace std;
const int maxn=805;
const int inf=999999;
vector<int> G[maxn];
int matching[maxn];
bool vis[maxn];
int Nx;
bool dfs(int u){
int N=G[u].size();
for(int i=0;i<N;i++){
int v=G[u][i];
if(vis[v])continue;
vis[v]=true;
if(matching[v]==-1||dfs(matching[v])){
matching[v]=u;
return true;
}
}
return false;
}
int hungar(){
int ans=0;
cl(matching,-1);
for(int i=0;i<Nx;i++){
cl(vis,false);
if(dfs(i))ans++;
}
return ans;
}
struct node{
int w,l,h;
}p[maxn];
int main(){
int n;
while(~scanf("%d",&n)&&n){
for(int i=0;i<n;i++){
scanf("%d%d%d",&p[i].w,&p[i].l,&p[i].h);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)if(j!=i&&p[i].w<p[j].w&&p[i].l<p[j].l&&p[i].h<p[j].h){
G[i].pb(j);
}
}
Nx=n;
int ans=hungar();
printf("%d\n",n-ans);
for(int i=0;i<=n;i++)G[i].clear();
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-26 16:08:56