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 ≤ ...
随机推荐
- java项目发布到linux服务器,tomcat正常启动但没加载项目
问题描述: java项目发布到linux服务器,一切操作正确,linux命令启动tomcat后,查看日志启动tomcat正常,上传的war包已经解压成功,但是tomcat没加载项目. 解决方法: 1. ...
- 基本DFS与BFS算法(C++实现)
样图: DFS:深度优先搜索,是一个不断探查和回溯的过程,每探查一步就将该步访问位置为true,接着在该点所有邻接节点中,找出尚未访问过的一个,将其作为下个探查的目标,接着对这个目标进行相同的操作,直 ...
- jenkins启动
1.已安装JDK,因为jenkins是一款基于java的持续集成工具 2.已配置tomcat,并安装maven 3.下载一个jenkins的war包,放在tomcat/webapps目录下 4.cmd ...
- 用SQL表达连接与外连接
关系代数运算中,有连接运算,又分为θ连接和外连接 标准SQL语言中连接运算通常是采用 SELECT 列名[[,列名]...] FROM 表名1,表名2,... WHERE 检索条件; SQL的高级语法 ...
- css-reset 代码
最常用 * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } *:bef ...
- Matcher.replaceFirst(String replacement)
java.util.regex.Matcher.replaceFirst(String replacement)方法是用来进行字符串的替换操作. public String replaceFirst( ...
- 20175306 迭代和JDB调试
迭代和JDB调试 1.使用C(n,m)=C(n-1,m-1)+C(n-1,m)公式进行递归编程实现求组合数C(m,n)的功能 代码展示: public class C { public static ...
- (四)ORBSLAM运动估计
ORBSLAM2的运动估计简介 ORBSLAM2中的运动估计核心方法就是3D-2D的PNP,而在跟踪过程主要分为三种类型: 无运动模型的跟踪,即基于参考帧的跟踪: 基于匀速运动模型的跟踪: 重定位: ...
- springboot接口访问权限AOP实现
场景 现在有个系统,很多接口只需要登录就可以访问,但是有些接口需要授予并验证权限.如果用注解controller的方式控制接口的权限呢? 1.注解声明代码 这个注解是要装饰在controller接口上 ...
- 常用的user32说明
函数名称 说明 ActiveKeyboardLayout 激活一个不同的键盘布局,该布局必须先由LoadKeyBoardLayout函数装载AdjustWindowRect 根据希望的用户矩形大小来计 ...