lg1034[NOIP2002 提高组] 矩形覆盖
-> k is small <=4 -> point is limited
------ -----------------------------------------------------------------------------
1.枚举矩形包围点 500^4 舍弃 -> dfs
2.dp -> k ->无状态
------------------------------------------------------------------------------------
3.->枚举点加入 ( add -> cross /in_node ->if_cross )
dfs -> ans-> get()
/* 4 2 1 1 2 2 3 6 0 7 4 */ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<bits/stdc++.h> #define ll long long #define ddd printf("-----------------debug\n"); using namespace std; int n,k,x[53],y[53],ans=0x3f3f3f; struct node { int ux,uy,dx,dy,use; void add(int x,int y) { if(use==0) { ux=x,dx=x,uy=y,dy=y; use=1; } else { if(x<ux) ux=x; if(x>dx) dx=x; if(y>uy) uy=y; if(y<dy) dy=y; } } int in_node(int x,int y){ if(use==0) return 0; if(x<ux||x>dx||y<dy||y>uy) return 0; return 1; } int get(){ return (dx-ux)*(uy-dy); } int cross(struct node u){ if(in_node(u.ux,u.uy)||in_node(u.ux,u.dy)||in_node(u.dx,u.uy)||in_node(u.dx,u.dy)) return 1; return 0; } }g[5]; int if_cross(){ for(int i=1;i<=k;i++) for(int j=i+1;j<=k;j++) if( g[i].cross(g[j]) || g[j].cross(g[i]) ) return 1; return 0; } void dfs(int area,int cur) { if(area>=ans) return ; if(cur==n+1) { if(if_cross()==0&&area<ans) ans=area; return ; } for(int i=1;i<=k;i++) { struct node t; t=g[i]; g[i].add(x[cur],y[cur]); dfs(area-t.get()+g[i].get(),cur+1); g[i]=t; } } int main() { ios::sync_with_stdio(false); cin>>n>>k; for(int i=1;i<=n;i++) cin>>x[i]>>y[i]; dfs(0,1); cout<<ans<<endl; return 0; }

浙公网安备 33010602011771号