Rectangular Covering [POJ2836] [状压DP]
题意
平面上有 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 x, y (−1,000 ≤ x, y ≤ 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]的更多相关文章
- POJ2836 Rectangular Covering(状压DP)
题目是平面上n个点,要用若干个矩形盖住它们,每个矩形上至少要包含2个点,问要用的矩形的面积和最少是多少. 容易反证得出每个矩形上四个角必定至少覆盖了两个点.然后就状压DP: dp[S]表示覆盖的点集为 ...
- POJ 2836 Rectangular Covering(状压DP)
[题目链接] http://poj.org/problem?id=2836 [题目大意] 给出二维平面的一些点,现在用一些非零矩阵把它们都包起来, 要求这些矩阵的面积和最小,求这个面积和 [题解] 我 ...
- 【POJ3254】Corn Fields 状压DP第一次
!!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostre ...
- poj3254 Corn Fields (状压DP)
http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- poj3254状压DP入门
G - 状压dp Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:65536KB 64bit ...
- 状压dp(状态压缩&&dp结合)学习笔记(持续更新)
嗯,作为一只蒟蒻,今天再次学习了状压dp(学习借鉴的博客) 但是,依旧懵逼·································· 这篇学习笔记是我个人对于状压dp的理解,如果有什么不对的 ...
- 状态压缩动态规划 状压DP
总述 状态压缩动态规划,就是我们俗称的状压DP,是利用计算机二进制的性质来描述状态的一种DP方式 很多棋盘问题都运用到了状压,同时,状压也很经常和BFS及DP连用,例题里会给出介绍 有了状态,DP就比 ...
- poj 3254Corn Fields (入门状压dp)
Farmer John has purchased a lush ≤ M ≤ ; ≤ N ≤ ) square parcels. He wants to grow some yummy corn fo ...
- POJ 1684 Corn Fields(状压dp)
描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...
随机推荐
- Debian Security Advisory DSA-4419-1 twig security update
Package : twigCVE ID : CVE-2019-9942 Fabien Potencier discovered that twig, a templat ...
- 理解 Linux 的硬链接与软链接【转】
转自:https://www.ibm.com/developerworks/cn/linux/l-cn-hardandsymb-links/index.html 从 inode 了解 Linux 文件 ...
- Python base64编码,转图片
我在做火车票抢票器的时候遇到一个问题,就是验证码提取的:一般验证码都是一些http请求的url,但是火车票网站遇到了我没有见过的以data:image/jpg;base64开头的字符串.现在我们就用P ...
- Rest分页接口开发
简单描述:需求说后端写一个XX数据的分页接口,给前端口调用,其实有一个PageHelper的工具类可以直接使用但是老大不让用,得用sql写,.小Kiss啦.直接上代码 代码: //Controller ...
- Photoshop 操作
本文主要记录在工作过程中使用ps的一些快捷键或操作顺序 1.ctrl+H:取消标尺 2.ctrl+D:取消选区 3.看矩形尺寸:选中矩形图层 >窗口 >属性(w:宽 H:高) 4.看图层 ...
- MySQL/Oracle数据库优化总结
MySQL数据库优化的八种方式 1.选取最适用的字段属性 MySQL可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快.因此,在创建表的时候,为了获得更好的性能 ...
- wxpy使用
一 简介 wxpy基于itchat,使用了 Web 微信的通讯协议,,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展.实现了微信登录.收发消息.搜索好友.数据统计等功能. 总而言之,可用来实 ...
- Anaconda安装python tensorflow 环境
1.安装Anaconda3 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 2.安装python 3.6 (base) C:\Users\ ...
- js属性对象的propertyIsEnumerable方法
定义 每个对象都有一个propertyIsEnumerable()方法.此方法返回一个布尔值,表明指定的属性是否是可枚举. This method can determine whether the ...
- sql--迁移条件数据和补全数值的一个流程
目的:我要把老顾客的部分数据迁移到另一个表里面 -- 步骤一:筛选查询-- 打开表,只显示想要看到的数据列-- 做条件筛选,筛选出想要的数据 -- 步骤二:sql查询 SELECT ID,Name,G ...