题意

平面上有 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

  1. 2
  2. 0 1
  3. 1 0
  4. 0

Sample Output

  1. 1

Analysis

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

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

Code

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <vector>
  5.  
  6. using std::vector;
  7. using std::min;
  8. using std::max;
  9.  
  10. const int MAXN = ;
  11. const int INF = 0x3f3f3f3f;
  12.  
  13. struct POINT
  14. {
  15. int x;
  16. int y;
  17. } p[MAXN + ];
  18.  
  19. struct RECTANGLE
  20. {
  21. int area;
  22. int cover;
  23. } r[MAXN * MAXN];
  24.  
  25. int n;
  26. int dp[ << MAXN];
  27. int area[MAXN + ][MAXN + ];
  28. int cnt;
  29.  
  30. int abs(int x)
  31. {
  32. return x > ? x : -x;
  33. }
  34.  
  35. void Read()
  36. {
  37. for (int i = ; i < n; ++i)
  38. {
  39. scanf("%d%d", &p[i].x, &p[i].y);
  40. }
  41. }
  42.  
  43. void Init()
  44. {
  45. cnt = ;
  46. for (int i = ; i < n; ++i)
  47. {
  48. for (int j = ; j < i; ++j)
  49. {
  50. if (j != i)
  51. {
  52. int width = abs(p[i].x - p[j].x) == ? : abs(p[i].x - p[j].x);
  53. int height = abs(p[i].y - p[j].y) == ? : abs(p[i].y - p[j].y);
  54. r[cnt].area = width * height;
  55. r[cnt].cover = ;
  56. for (int k = ; k < n; ++k)
  57. {
  58. if (p[k].x >= min(p[i].x, p[j].x) && p[k].x <= max(p[i].x, p[j].x) &&
  59. p[k].y >= min(p[i].y, p[j].y) && p[k].y <= max(p[i].y, p[j].y))
  60. {
  61. r[cnt].cover |= ( << k);
  62. }
  63. }
  64. ++cnt;
  65. }
  66. }
  67. }
  68. }
  69.  
  70. void Dp()
  71. {
  72. memset(dp, 0x3f, sizeof(dp));
  73. dp[] = ;
  74. for (int S = ; S < ( << n); ++S)
  75. {
  76. if (dp[S] != INF)
  77. {
  78. for (int i = ; i < cnt; ++i)
  79. {
  80. int news = S | r[i].cover;
  81. if (news != S)
  82. {
  83. dp[news] = min(dp[news], dp[S] + r[i].area);
  84. }
  85. }
  86. }
  87. }
  88. printf("%d\n", dp[( << n) - ]);
  89. }
  90.  
  91. int main()
  92. {
  93. while (scanf("%d", &n) == && n)
  94. {
  95. Read();
  96. Init();
  97. Dp();
  98. }
  99.  
  100. return ;
  101. }

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. java项目发布到linux服务器,tomcat正常启动但没加载项目

    问题描述: java项目发布到linux服务器,一切操作正确,linux命令启动tomcat后,查看日志启动tomcat正常,上传的war包已经解压成功,但是tomcat没加载项目. 解决方法: 1. ...

  2. 基本DFS与BFS算法(C++实现)

    样图: DFS:深度优先搜索,是一个不断探查和回溯的过程,每探查一步就将该步访问位置为true,接着在该点所有邻接节点中,找出尚未访问过的一个,将其作为下个探查的目标,接着对这个目标进行相同的操作,直 ...

  3. jenkins启动

    1.已安装JDK,因为jenkins是一款基于java的持续集成工具 2.已配置tomcat,并安装maven 3.下载一个jenkins的war包,放在tomcat/webapps目录下 4.cmd ...

  4. 用SQL表达连接与外连接

    关系代数运算中,有连接运算,又分为θ连接和外连接 标准SQL语言中连接运算通常是采用 SELECT 列名[[,列名]...] FROM 表名1,表名2,... WHERE 检索条件; SQL的高级语法 ...

  5. css-reset 代码

    最常用 * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } *:bef ...

  6. Matcher.replaceFirst(String replacement)

    java.util.regex.Matcher.replaceFirst(String replacement)方法是用来进行字符串的替换操作. public String replaceFirst( ...

  7. 20175306 迭代和JDB调试

    迭代和JDB调试 1.使用C(n,m)=C(n-1,m-1)+C(n-1,m)公式进行递归编程实现求组合数C(m,n)的功能 代码展示: public class C { public static ...

  8. (四)ORBSLAM运动估计

    ORBSLAM2的运动估计简介 ORBSLAM2中的运动估计核心方法就是3D-2D的PNP,而在跟踪过程主要分为三种类型: 无运动模型的跟踪,即基于参考帧的跟踪: 基于匀速运动模型的跟踪: 重定位: ...

  9. springboot接口访问权限AOP实现

    场景 现在有个系统,很多接口只需要登录就可以访问,但是有些接口需要授予并验证权限.如果用注解controller的方式控制接口的权限呢? 1.注解声明代码 这个注解是要装饰在controller接口上 ...

  10. 常用的user32说明

    函数名称 说明 ActiveKeyboardLayout 激活一个不同的键盘布局,该布局必须先由LoadKeyBoardLayout函数装载AdjustWindowRect 根据希望的用户矩形大小来计 ...