全班都进前50的屑 • 2年前
/By SilverN/
using namespace std; int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
} struct point{
int x,y;
}a[60]; int cmp(point a,point b){
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
} struct block{
int x1,y1,x2,y2;
}b[5]; int n,k; int ans=1e9; void DFS(int pos,int cnt,int smm){
if(pos>n){
ans=min(ans,smm);
return;
}
if(cnt>k)return;
int i,j;
b[cnt].x1=a[pos].x;
b[cnt].x2=a[pos].x;
b[cnt].y1=a[pos].y;
b[cnt].y2=a[pos].y;
for(i=pos;i<=n;i++){
b[cnt].y2=max(b[cnt].y2,a[i].y);
b[cnt].x2=max(b[cnt].x2,a[i].x);
b[cnt].x1=min(b[cnt].x1,a[i].x);
b[cnt].y1=min(b[cnt].y1,a[i].y);
for(j=1;j<cnt;j++){
if(b[cnt].x1<=b[j].x2 && b[cnt].y1<=b[j].y2)return;
}
if(i<n && cnt==k)continue;
DFS(i+1,cnt+1,smm+(b[cnt].x2-b[cnt].x1)*(b[cnt].y2-b[cnt].y1));
}
return;
} int main(){
n=read();k=read();
int i,j;
for(i=1;i<=n;i++){
a[i].y=read();a[i].x=read();
}
sort(a+1,a+n+1,cmp);
memset(b,-1,sizeof b);
DFS(1,1,0);
printf("%d\n",ans);
return 0;
}
评论:
请先登录,才能进行评论