POJ 2836 Rectangular Covering (状压DP)
题意:平面上有 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)的更多相关文章
- poj 2836 Rectangular Covering(状态压缩dp)
Description n points are given on the Cartesian plane. Now you have to use some rectangles whose sid ...
- POJ 3254 - Corn Fields - [状压DP水题]
题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...
- POJ 3254 Corn Fields (状压dp)
题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压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 ≤ ...
- [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp
题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...
- POJ 2923 Relocation(状压DP)题解
题意:有2辆车运货,每次同时出发,n(<10),各自装货容量c1 c2,问最少运几次运完. 思路:n比较小,打表打出所有能运的组合方式,用背包求出是否能一次运走.然后状压DP运的顺序. 代码: ...
- poj 2836 Rectangular Covering
Rectangular Covering Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2776 Accepted: 7 ...
- POJ 2836 Rectangular Covering(状压DP)
[题目链接] http://poj.org/problem?id=2836 [题目大意] 给出二维平面的一些点,现在用一些非零矩阵把它们都包起来, 要求这些矩阵的面积和最小,求这个面积和 [题解] 我 ...
随机推荐
- HihoCoder1366 逆序单词(字典树)
逆序单词 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在英文中有很多逆序的单词,比如dog和god,evil和live等等. 现在给出一份包含N个单词的单词表,其中每 ...
- 每天一个linux命令(14):less命令
版权声明更新:2017-05-18博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下面的mv命令. 2. ...
- sort--Linux下文本处理五大神器之三
转自:http://www.cnblogs.com/dong008259/archive/2011/12/08/2281214.html sort命令是帮我们依据不同的数据类型进行排序,其语法及常用参 ...
- Oracle使用总结一
一.修改表名要修改索引以及主键 ALTER TABLE AFA_AUTH_FUNCTION RENAME TO BACK_AFA_AUTH_FUNCTION ----修改表名 alter table ...
- [推荐]InfoQ上的深入浅出Node.js的系列文章
InfoQ上的深入浅出Node.js的系列文章 详情如下链接:http://www.heiboard.com/?p=2081
- GPIO编程2:使用GPIO监听中断完整程序
一个完整的使用GPIO捕捉中断的程序: #include<stdlib.h> #include<stdio.h> #include<string.h> #inclu ...
- Day3(1)linux文件系统及文件类型
Linux的文件系统 根文件系统(rootfs) root filesystem LSB,FHS:(FileSystem Heirache Standard) /etc,/usr,/var,/root ...
- 让32位应用程序不再为2G内存限制苦恼
最近在做个程序,虽然是小型程序,但是使用的内存量却很大,动辄达到10G.在64位系统上可以轻松实现,无奈我是基于32位的系统进行开发,程序还没跑起来就已经被终止了. 试过很多办法,包括文件内 ...
- Java中实现MongoDB自增主键ID
1.了解MongoDB的ObjectId MongoDB的文档固定是使用“_id”作为主键的,它可以是任何类型的,默认是个ObjectId对象(在Java中则表现为字符串),那么为什么M ...
- 四川第七届 E Rectangle
Rectangle frog has a piece of paper divided into nn rows and mm columns. Today, she would like to dr ...