题意

平面上有 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. idea2018注册

    1.在网上随便找一个注册码,lanyu的即可,注册时会被提示此注册码已被取消. 2.修改hosts文件,目录:C:\Windows\System32\drivers\etc\hosts,在文件中添加  ...

  2. Convolutional Pose Machines(理解)

    0 - 背景 人体姿态识别存在遮挡以及关键点不清晰等主要挑战,然而,人体的关键点之间由于人体结构而具有相互关系,利用容易识别的关键点来指导难以识别关键点的检测,是提高关键点检测的一个思路.本文通过提出 ...

  3. 软件测试为什么需要学习Linux的知识?Linux学到什么程度?-log5

    ​软件测试为什么需要学习Linux的知识?学到什么程度?-log5 Dotest软件测试学堂-董浩 公司目前90%的服务器操作系统不是Windows,而是Linux(RedHat.Debian.Cen ...

  4. C#使用RabbitMQ(转)

      1. 说明 在企业应用系统领域,会面对不同系统之间的通信.集成与整合,尤其当面临异构系统时,这种分布式的调用与通信变得越发重要.其次,系统中一般会有很多对实时性要求不高的但是执行起来比较较耗时的地 ...

  5. 使用docker中mysql镜像

    1.拉取mysql镜像 docker pull mysql:5.6 2.运行mysql的镜像生成一个正在运行的容器,可以通过docker contain ls得到容器的id信息 docker run ...

  6. LibreOJ一本通题解报告

    网页跳转 解析啥的以后会有的 目录 ·T1活动安排 ·T2种树 ·T3喷水装置 T1活动安排 /* problem:yibentong10000 date:2019/4/21 author:Lonel ...

  7. nginx+uwsgi+django开发环境搭建

    Nginx+uWSGI+Djangoi开发环境搭建 Django简介,环境搭建 uWSGI简介,安装与配置 Nginx安装与配置 Nginx+uWSGI+Django原理解析 1.django简介,环 ...

  8. 三, 练习 python索引 (list和tuple)

    (1) 练习 请用索引取出下面list的指定元素: 1, # -*- coding: utf-8 -*- L = [ ['Apple', 'Google', 'Microsoft'], ['Java' ...

  9. xgb

    xgb原理 xgb代码

  10. Scyther-Semantics and verification of Security Protocol

    1 .本书前一节主要是介作者自己的生平经历(读完感觉作者是个神童),目标明确作者13岁代码已经写的很溜了.自己也开了网络公司,但是后面又专注于自己的计算机基础理论,修了哲学的博士学位(不得不说很多专业 ...