题意:平面上有 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. RabbitMQ集群 Docker一键部署

    以下内容来自网络转载 步骤1. 安装docker 以centos7为例,https://docs.docker.com/engine/installation/linux/centos/ 步骤2. 创 ...

  2. mysql之 double write 浅析

    http://blog.itpub.net/22664653/viewspace-1140915/ 介绍double write之前我们有必要了解partial page write 问题 :     ...

  3. Redis 分布式锁 - 分布式锁的正确实现方式

    前言 分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布式锁:3. 基于ZooKeeper的分布式锁.本篇博客将介绍第二种方式,基于Redis实现分布式锁.虽然网上已经有各种介 ...

  4. 在centos阿里云服务器上安装配置php运行环境 安装php7

    http://blog.csdn.net/kesixin/article/details/72882469 单独安装php7 http://blog.csdn.net/tang05709/articl ...

  5. 布同:使用ghost备份或者还原的往事

    我大学的时候经常折腾电脑,安装了不少莫名其妙的东西.当时对各种小软件特别感兴趣,本着毕业后可以做客户端开发的初衷去做事情.不过很多小软件会恶意安装各种东西,修改注册表,时间一长就会导致C盘很臃肿,必须 ...

  6. Java基础--读写文件

    Java读写文件需要注意异常的处理,下面是一个例子 写文件 public class WriteFile { public static void write(String file, String ...

  7. ISE(Iris Server Engine)是一个基于现代C++的跨平台(Linux和Windows)框架

    ISE(Iris Server Engine)是一个基于现代C++的跨平台(Linux和Windows)的高性能多线程并发网络服务器程序框架.它封装了琐碎的socket以及各种操作系统APIs,以面向 ...

  8. js页面埋点

    页面埋点的作用,其实就是用于流量分析.而流量的意思,包含了很多:页面浏览数(PV).独立访问者数量(UV).IP.页面停留时间.页面操作时间.页面访问次数.按钮点击次数.文件下载次数等.而流量分析又有 ...

  9. c++如何编写线程安全的DLL

    DLL有个共同的特点就是都有一个初始化函数,一个资源释放函数,其他几个函数都是核心功能函数.而且这些DLL有时会被多个进程同时调用,这就牵扯到多进程的多线程调用DLL的问题.有点绕口,以下我根据我实践 ...

  10. Solaris ssh配置主机间信任关系

    假设需要配置从主机com00biiitf001登录主机ols00biiitf001时不需要密码,则采用以下步骤配置: com00biiitf001上产生公用/私有密钥对 $ ssh-keygen -t ...