题目是平面上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. SGU 180 Inversions(离散化 + 线段树求逆序对)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...

  2. ini 文件操作记要(1): 使用 TIniFile

    ini 文件操作记要(1): 使用 TIniFile unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Class ...

  3. Android Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法

    在Android开发中,ListView有着很重要的地位,使用的场合也非常的多 错误提示:Your content must have a ListView whose id attribute is ...

  4. Java for LeetCode 147 Insertion Sort List

    Sort a linked list using insertion sort. 解题思路: 插入排序,JAVA实现如下: public ListNode insertionSortList(List ...

  5. JavaScript封装成类

    JavaScript在WEB编程中能起到很大的作用,将一些常用的功能写成JavaScript类库. 将下面代码保存为Common.js 类库功能: 1.Trim(str)--去除字符串两边的空格 2. ...

  6. 【python】队列

    来源:http://www.cnblogs.com/yupeng/p/3413852.html 关于队列 >>> from collections import deque > ...

  7. NEFU 1146 又见A+B

    又见a+b Problem:1146 Time Limit:1000ms Memory Limit:65535K Description 给定两个非负整数A,B,求他们的和. Input 多组输入,每 ...

  8. August 3rd, 2016, Week 32nd, Wednesday

    I am looking for someone to share in an adventure. 我在找能和我一起分享冒险之旅的人. We are all looking for someone ...

  9. jsp url传值乱码

    <Connector port="8080" maxHttpHeaderSize="8192" minProcessors="10"  ...

  10. loadingDialog

    1.dialog布局 dialog_loading.xml <?xml version="1.0" encoding="utf-8"?> <L ...