题目是平面上n个点,要用若干个矩形盖住它们,每个矩形上至少要包含2个点,问要用的矩形的面积和最少是多少。

容易反证得出每个矩形上四个角必定至少覆盖了两个点。然后就状压DP:

  • dp[S]表示覆盖的点集为S要用的最少矩形面积

转移我一开始是未覆盖的点和已覆盖的点构成一个矩形来转移,这是错的,因为这样子的结果是所有矩形都相连的最小面积和。

正确的是枚举还未被覆盖的矩形来转移。转移我用我为人人+队列。

有一点要注意的是,覆盖(0,0)和(0,2)两点要用的矩形是1*2,所以要特判一下两点斜率0或不存在时构成的矩形。

 #include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define INF (1<<29) bool isIn(int x1,int y1,int x2,int y2,int x,int y){
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
return x1<=x && x<=x2 && y1<=y && y<=y2;
}
int area(int x1,int y1,int x2,int y2){
if(x1==x2) ++x2;
if(y1==y2) ++y2;
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
return (x2-x1)*(y2-y1);
}
int d[<<],sta[][];
bool inque[<<];
int main(){
int n,x[],y[];
while(~scanf("%d",&n) && n){
for(int i=; i<n; ++i) scanf("%d%d",x+i,y+i);
for(int i=; i<(<<n); ++i) d[i]=INF;
queue<int> que;
memset(inque,,sizeof(inque));
for(int i=; i<n; ++i){
for(int j=i+; j<n; ++j){
int s=;
for(int k=; k<n; ++k){
if(isIn(x[i],y[i],x[j],y[j],x[k],y[k])) s|=(<<k);
}
sta[i][j]=sta[j][i]=s;
if(d[s]>area(x[i],y[i],x[j],y[j])){
d[s]=area(x[i],y[i],x[j],y[j]);
if(!inque[s|sta[i][j]]){
inque[s]=;
que.push(s);
}
}
}
}
while(!que.empty()){
int s=que.front(); que.pop();
for(int i=; i<n; ++i){
for(int j=i+; j<n; ++j){
if(((s>>i)&) && ((s>>j)&)) continue;
if(d[s|sta[i][j]]>d[s]+area(x[i],y[i],x[j],y[j])){
d[s|sta[i][j]]=d[s]+area(x[i],y[i],x[j],y[j]);
if(!inque[s|sta[i][j]]){
inque[s|sta[i][j]]=;
que.push(s|sta[i][j]);
}
}
}
}
inque[s]=;
}
printf("%d\n",d[(<<n)-]);
}
return ;
}

POJ2836 Rectangular Covering(状压DP)的更多相关文章

  1. POJ 2836 Rectangular Covering (状压DP)

    题意:平面上有 n (2 ≤ n ≤ 15) 个点,现用平行于坐标轴的矩形去覆盖所有点,每个矩形至少盖两个点,矩形面积不可为0,求这些矩形的最小面积. 析:先预处理所有的矩形,然后dp[s] 表示 状 ...

  2. 【POJ3254】Corn Fields 状压DP第一次

    !!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostre ...

  3. poj3254 Corn Fields (状压DP)

    http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

  4. poj3254状压DP入门

    G - 状压dp Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:65536KB     64bit ...

  5. 状压dp(状态压缩&&dp结合)学习笔记(持续更新)

    嗯,作为一只蒟蒻,今天再次学习了状压dp(学习借鉴的博客) 但是,依旧懵逼·································· 这篇学习笔记是我个人对于状压dp的理解,如果有什么不对的 ...

  6. 状态压缩动态规划 状压DP

    总述 状态压缩动态规划,就是我们俗称的状压DP,是利用计算机二进制的性质来描述状态的一种DP方式 很多棋盘问题都运用到了状压,同时,状压也很经常和BFS及DP连用,例题里会给出介绍 有了状态,DP就比 ...

  7. poj 3254Corn Fields (入门状压dp)

    Farmer John has purchased a lush ≤ M ≤ ; ≤ N ≤ ) square parcels. He wants to grow some yummy corn fo ...

  8. POJ 1684 Corn Fields(状压dp)

    描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...

  9. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

随机推荐

  1. shell kill掉含同一字符的关键字的进程

    如何kill掉进程名包含某个字符串的一批进程:kill -9 $(ps -ef|grep 进程名关键字|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') 观 ...

  2. spring原理

    1.spring框架什么时候被加载? (1)ApplicationContext ac = new ClassPathXmlApplicationContext("applicationCo ...

  3. Java中Properties类的操作

    知识学而不用,就等于没用,到真正用到的时候还得重新再学.最近在看几款开源模拟器的源码,里面涉及到了很多关于Properties类的引用,由于Java已经好久没用了,而这些模拟器大多用Java来写,外加 ...

  4. Windows/Centos安装GO语言环境

    转载:http://www.haiyun.me/archives/1009.html Centos下使用epel源安装: 1 yum install golang Centos/Linux下源码安装g ...

  5. 【Python】python list 迭代删除

    最好方式使用filter,代码示例: def _filter(self, item): ): return False return True #lambda e:e%!= data['items'] ...

  6. 《ASP.NET MVC4 WEB编程》学习笔记------Web API 续

    目录 ASP.NET WEB API的出现缘由 ASP.NET WEB API的强大功能 ASP.NET WEB API的出现缘由 随着UI AJAX 请求适量的增加,ASP.NET MVC基于Jso ...

  7. Encode and Decode Strings

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  8. div隐藏

    <div style="display:none">                 <textarea id="BodyBox2" runa ...

  9. HDU 2588 GCD (欧拉函数)

    GCD Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status De ...

  10. CodeForces - 404B(模拟题)

    Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...