题意

平面上有 n (2 ≤ n ≤ 15) 个点,现用平行于坐标轴的矩形去覆盖所有点,每个矩形至少盖两个点,矩形面积不可为0,求这些矩形的最小面积。

Input

The input consists of several test cases. Each test cases begins with a line containing a single integer n (2 ≤ n ≤ 15). Each of the next n lines contains two integers xy (−1,000 ≤ xy ≤ 1,000) giving the coordinates of a point. It is assumed that no two points are the same as each other. A single zero follows the last test case.

Output

Output the minimum total area of rectangles on a separate line for each test case.

Sample Input

2
0 1
1 0
0

Sample Output

1

Analysis

枚举两个个点,再算包含在这两个点的点,算进一个矩形

然后在枚举矩形,进行状压DP

Code

 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector> using std::vector;
using std::min;
using std::max; const int MAXN = ;
const int INF = 0x3f3f3f3f; struct POINT
{
int x;
int y;
} p[MAXN + ]; struct RECTANGLE
{
int area;
int cover;
} r[MAXN * MAXN]; int n;
int dp[ << MAXN];
int area[MAXN + ][MAXN + ];
int cnt; int abs(int x)
{
return x > ? x : -x;
} void Read()
{
for (int i = ; i < n; ++i)
{
scanf("%d%d", &p[i].x, &p[i].y);
}
} void Init()
{
cnt = ;
for (int i = ; i < n; ++i)
{
for (int j = ; j < i; ++j)
{
if (j != i)
{
int width = abs(p[i].x - p[j].x) == ? : abs(p[i].x - p[j].x);
int height = abs(p[i].y - p[j].y) == ? : abs(p[i].y - p[j].y);
r[cnt].area = width * height;
r[cnt].cover = ;
for (int k = ; k < n; ++k)
{
if (p[k].x >= min(p[i].x, p[j].x) && p[k].x <= max(p[i].x, p[j].x) &&
p[k].y >= min(p[i].y, p[j].y) && p[k].y <= max(p[i].y, p[j].y))
{
r[cnt].cover |= ( << k);
}
}
++cnt;
}
}
}
} void Dp()
{
memset(dp, 0x3f, sizeof(dp));
dp[] = ;
for (int S = ; S < ( << n); ++S)
{
if (dp[S] != INF)
{
for (int i = ; i < cnt; ++i)
{
int news = S | r[i].cover;
if (news != S)
{
dp[news] = min(dp[news], dp[S] + r[i].area);
}
}
}
}
printf("%d\n", dp[( << n) - ]);
} int main()
{
while (scanf("%d", &n) == && n)
{
Read();
Init();
Dp();
} return ;
}

Rectangular Covering [POJ2836] [状压DP]的更多相关文章

  1. POJ2836 Rectangular Covering(状压DP)

    题目是平面上n个点,要用若干个矩形盖住它们,每个矩形上至少要包含2个点,问要用的矩形的面积和最少是多少. 容易反证得出每个矩形上四个角必定至少覆盖了两个点.然后就状压DP: dp[S]表示覆盖的点集为 ...

  2. POJ 2836 Rectangular Covering(状压DP)

    [题目链接] http://poj.org/problem?id=2836 [题目大意] 给出二维平面的一些点,现在用一些非零矩阵把它们都包起来, 要求这些矩阵的面积和最小,求这个面积和 [题解] 我 ...

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

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

  4. poj3254 Corn Fields (状压DP)

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

  5. poj3254状压DP入门

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

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

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

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

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

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

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

  9. POJ 1684 Corn Fields(状压dp)

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

随机推荐

  1. cmd切换代码页,切换字体,cmd不能输入中文

    cmd终端切换编码:437:美国英语.936:中文gbk编码.65001:UTF8 小知识: 如果cmd不能调用中文输入法,也就是不能输入中文,是因为目前激活的代码页不是936 使用 chcp 936 ...

  2. Linux中查看端口占用情况

    1.lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口的使用情况: # lsof -i:8000 2.netstat -tunlp | grep 端口号,用于查看指定的端口号的进 ...

  3. Oracle SQL性能优化总结

    1. SQL语句执行步骤 语法分析> 语义分析> 视图转换 >表达式转换> 选择优化器 >选择连接方式 >选择连接顺序 >选择数据的搜索路径 >运行“执 ...

  4. tar解压指定文件

    import tarfileimport sys#tar = tarfile.open('/opt/platform-omp/omp.tar.gz','r')tar = tarfile.open(r' ...

  5. APP的三种开发模式

    转载于http://pleasureswx123.github.io/2014/09/15/APP%E7%9A%84%E4%B8%89%E7%A7%8D%E5%BC%80%E5%8F%91%E6%A8 ...

  6. 【转】子类会调用父类的@PostConstruct方法

    如果一个类用@Service或@Component,那么只需要用@PostConstruct修饰某个方法,该方法能在类实例化的过程中自动执行,相当于类的构造函数.同时,具备了构造函数不具备的功能. @ ...

  7. 前端笔记知识点整合之JavaScript(三)关于条件判断语句、循环语句那点事

      一.条件分支语句 条件分支语句,也叫作条件判断语句,就是根据某种条件执行某些语句,不执行某些语句. JS中有三种语法是可以表示条件分支的 1.1 if……else…… 条件分支的主力语法,这个主力 ...

  8. 适用于typecho0.9的评论表情插件

    依旧是寻找插件,实在是太累人,很多插件现在更新后不支持typecho0.9了,今天想给评论框加一个表情拓展,发现新版本的插件完全不兼容typecho0.9,无奈用回旧版本····· 实际上,旧版本的插 ...

  9. Gitlab_ansible_jenkins三剑客④jenkins安装图解及freestyle的简单使用

    java环境准备 # 安装jdk1.8 [root@node02 ~]# rpm -ivh jdk-8u181-linux-x64.rpm vim /etc/profile export JAVA_H ...

  10. 【MySQL】MySQL基础操作语句

    mysql基础操作语句,包括数据库的增.删.切换,以及表的增.删.改.查.复制. 创建数据库 mysql> create database tem; 使用数据库 mysql> use te ...