题意

平面上有 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. move_base Warning: Invalid argument "/map" passed to canTransform argument target_frame的解决方法

    把global_costmap_params.yaml和local_costmap_params.yaml文件里的头几行去掉“/”,然后重新编译就可以了. 效果如下:

  2. jquery获取value值时将数字型字符串前面的0自动截取处理方法

    <li class="cwhite" value="02" id="02" onclick="getQuestionList ...

  3. Android logcat lines missing原因分析

    当出现类似如下错误日志时: 2019-04-14 17:51:14.506 10189-10189/com.ss.android.ex.parent D/GGK: no WonderfulVideo ...

  4. 2018-2019-2 网络对抗技术 20165325 Exp3 免杀原理与实践

    2018-2019-2 网络对抗技术 20165325 Exp3 免杀原理与实践 实验内容(概要) 一.正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion,自己 ...

  5. Socketserver的源码分析

    Socketserver的源码分析        

  6. 【转】Setting up SDL 2 on Visual Studio 2010 Ultimate

    from: Lazy Foo'Productions - Setting up SDL 2 on Visual Studio 2010 Ultimate 1)First thing you need ...

  7. Oracle XMLTYPE数据类型创建及插入

    --1.创建xml表Create TABLE testxml2(id NUMBER,data XMLTYPE); --2.插入数据--1)创建目录 CREATE or replace DIRECTOR ...

  8. Lua模式匹配

    Lua并不使用POSIX规范的正则表达式[4](也写作regexp)来进行模式匹配.主要的原因出于程序大小方面的考虑:实现一个典型的符合POSIX标准的regexp大概需要4000行代码,这比整个Lu ...

  9. 解决exlipse下 springboot 错误:找不到或无法加载主类

    简单描述:控制台出现了下图 废话不多说,直接上解决办法: 方法一:如果你很有自信,自己的pom 没问题,并且已经加载了所有依赖的jar.ok,这是eclipse的问题,window=>prefe ...

  10. iOS开发之HTTP与HTTPS网络请求

    HTTP是互联网中应用最为广泛的一种网络协议,在进入正文之前,先解释什么是网络协议?网络协议为计算机网络中进行数据交换而建立的规则.标准或约定的集合.网络协议是由以下三个要素组成:语义.语法.时序.国 ...