题意:平面上有 n (2 ≤ n ≤ 15) 个点,现用平行于坐标轴的矩形去覆盖所有点,每个矩形至少盖两个点,矩形面积不可为0,求这些矩形的最小面积。

析:先预处理所有的矩形,然后dp[s] 表示 状态 s 时,最少需要的面积是多少。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100000 + 10;
const int mod = 100000000;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int x[20], y[20];
struct Node{
int area, cover;
Node(int s,int c) : area(s), cover(c) { }
};
vector<Node> rec; void calc(int i, int j, int &s, int &cover){
int w = max(abs(x[i] - x[j]), 1);
int l = max(abs(y[i] - y[j]), 1);
s = w * l;
cover = 0;
int minx = min(x[i], x[j]);
int maxx = max(x[j], x[i]);
int miny = min(y[i], y[j]);
int maxy = max(y[j], y[i]);
for(int i = 0; i < n; ++i)
if(x[i] >= minx && y[i] <= maxy && x[i] <= maxx && y[i] >= miny) cover |= 1<<i;
} int dp[1<<15]; int main(){
while(scanf("%d", &n) == 1 && n){
rec.clear();
for(int i = 0; i < n; ++i)
scanf("%d %d", x+i, y+i);
for(int i = 1; i < n; ++i)
for(int j = 0; j < i; ++j){
int cover, s;
calc(i, j, s, cover);
rec.push_back(Node(s, cover));
}
memset(dp, INF, sizeof dp);
dp[0] = 0;
int all = 1 << n;
for(int j = 0; j < rec.size(); ++j){
Node &u = rec[j];
for(int i = 0; i < all; ++i){
if(dp[i] == INF) continue;
dp[i|u.cover] = min(dp[i|u.cover], dp[i] + u.area);
}
}
printf("%d\n", dp[all-1]);
}
return 0;
}

  

POJ 2836 Rectangular Covering (状压DP)的更多相关文章

  1. poj 2836 Rectangular Covering(状态压缩dp)

    Description n points are given on the Cartesian plane. Now you have to use some rectangles whose sid ...

  2. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  3. POJ 3254 Corn Fields (状压dp)

    题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...

  4. poj 3254Corn Fields (入门状压dp)

    Farmer John has purchased a lush ≤ M ≤ ; ≤ N ≤ ) square parcels. He wants to grow some yummy corn fo ...

  5. POJ 1684 Corn Fields(状压dp)

    描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...

  6. [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp

    题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...

  7. POJ 2923 Relocation(状压DP)题解

    题意:有2辆车运货,每次同时出发,n(<10),各自装货容量c1 c2,问最少运几次运完. 思路:n比较小,打表打出所有能运的组合方式,用背包求出是否能一次运走.然后状压DP运的顺序. 代码: ...

  8. poj 2836 Rectangular Covering

    Rectangular Covering Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2776   Accepted: 7 ...

  9. POJ 2836 Rectangular Covering(状压DP)

    [题目链接] http://poj.org/problem?id=2836 [题目大意] 给出二维平面的一些点,现在用一些非零矩阵把它们都包起来, 要求这些矩阵的面积和最小,求这个面积和 [题解] 我 ...

随机推荐

  1. linux下的制作静态库并使用它

    静态库所要用的源文件 文件 fred.c   #include <stdio.h>   void fred(int argc) {     printf("void fred(i ...

  2. Linux命令学习(17):ifconfig命令

    版权声明更新:2017-05-22博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 我们知道,在windows中,除了在图形界 ...

  3. Shiro-Session

    概述 Shiro提供了完整的企业级会话管理功能,不依赖于底层容器(如web容器tomcat),不管JavaSE还是JavaEE环境都可以使用,提供了会话管理.会话事件监听.会话存储/持久化.容器无关的 ...

  4. Codeforces 786C. Till I Collapse 主席树

    题目大意: 给定一个长度为\(n\)的序列,要求将其划分为最少的若干段使得每段中不同的数字的种数不超过\(k\). 对于 \(k = 1 .. n\)输出所有的答案. \(n \leq 10^5\) ...

  5. 高性能服务器架构 的几个注意点 (High-Performance Server Architecture)

    High-Performance Server Architecture 高性能服务器架构 来源:http://pl.atyp.us/content/tech/servers.html译文来源:htt ...

  6. keepalived之 ipvsadm-1.26-4(lvs)+ keepalived-1.2.24 安装

    一.安装 LVS 前提:已经提前配置好本地 Yum 源 配置过程可参考> http://blog.csdn.net/zhang123456456/article/details/56690945 ...

  7. Process使用

    最近在一个项目中,需要在C#中调用cmd窗口来执行一个命令,使用到了Process这个类,使用过程中遇到不少问题,好在终于解决了.赶紧记录下来. Process process = new Proce ...

  8. JQ选择器大全

    jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法 $("#myELement") 选择id值等于myElement的元素,id值不能重复在文档中只能有一个 ...

  9. Disconf —— 来自百度的分布式配置管理平台

    摘要 为了更好的解决分布式环境下多台服务实例的配置统一管理问题,本文提出了一套完整的分布式配置管理解决方案(简称为disconf[4],下同).首先,实现了同构系统的配置发布统一化,提供了配置服务se ...

  10. 类型:Oracle;问题:oracle 查询表详细信息;结果:oracle查询表信息(索引,外键,列等)

    oracle查询表信息(索引,外键,列等) oracle中查询表的信息,包括表名,字段名,字段类型,主键,外键唯一性约束信息,索引信息查询SQL如下,希望对大家有所帮助: 1.查询出所有的用户表sel ...