POJ 2836 Rectangular Covering(状压DP)
【题目链接】 http://poj.org/problem?id=2836
【题目大意】
给出二维平面的一些点,现在用一些非零矩阵把它们都包起来,
要求这些矩阵的面积和最小,求这个面积和
【题解】
我们计算出以每两个点为矩形顶点所构成的矩形面积和包含的点子集,
然后对这些子集进行状态DP,求全集的最小覆盖
【代码】
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
const int N=16;
int n,dp[1<<N],x[N],y[N];
struct Rect{
int coverd,area;
Rect(const int& coverd,const int& area):coverd(coverd),area(area){}
void add(int i){coverd|=1<<i;}
};
bool in(int i,int j,int k){return((x[i]-x[k])*(x[j]-x[k])<=0)&&((y[i]-y[k])*(y[j]-y[k])<=0);}
int main(){
while(scanf("%d",&n)&&n){
for(int i=0;i<n;i++)scanf("%d%d",&x[i],&y[i]);
vector<Rect> VR;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
Rect r((1<<i)|(1<<j),max(1,abs(x[i]-x[j]))*max(1,abs(y[i]-y[j])));
if(i!=j)for(int k=0;k<n;k++)if(in(i,j,k))r.add(k);
VR.push_back(r);
}
}memset(dp,0x3f,sizeof(dp));
dp[0]=0; vector<Rect>::iterator it;
for(it=VR.begin();it!=VR.end();it++){
for(int s=0;s<(1<<n);s++){
int ns=s|it->coverd;
if(ns!=s)dp[ns]=min(dp[ns],dp[s]+it->area);
}
}printf("%d\n",dp[(1<<n)-1]);
}return 0;
}
POJ 2836 Rectangular Covering(状压DP)的更多相关文章
- POJ 2836 Rectangular Covering (状压DP)
题意:平面上有 n (2 ≤ n ≤ 15) 个点,现用平行于坐标轴的矩形去覆盖所有点,每个矩形至少盖两个点,矩形面积不可为0,求这些矩形的最小面积. 析:先预处理所有的矩形,然后dp[s] 表示 状 ...
- 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 ...
随机推荐
- Linq语法和C#6.0
一. linq 1.简介: 能用linq实现的基本都可以用扩展方法实现: 举例: 查询ID>1的狗有如下两种写法 (1)var r1=dogs.where(d=>d.id>1) ( ...
- Python全栈工程师(每周总结:2)
ParisGabriel 感谢 大家的支持 每天坚持 一天一篇 点个订 ...
- Python全栈工程师(字符串/序列)
ParisGabriel Python 入门基础 字符串:str用来记录文本信息字符串的表示方式:在非注释中凡是用引号括起来的部分都是字符串‘’ 单引号“” 双引号''' ''' ...
- Opencv3.3.1安装包
这个资源是Opencv3.3.1安装包,包括Windows软件包,Android软件包,IOS软件包,还有opencv的源代码:需要的下载吧. 点击下载
- BZOJ 2186 沙拉公主的困惑
2186: [Sdoi2008]沙拉公主的困惑 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 3397 Solved: 1164 [Submit] ...
- 积累: .net里有个线程安全的int+1类
Interlocked.Increment(ref id);
- 【DNS】DNS的几个基本概念
一. 根域 就是所谓的“.”,其实我们的网址www.baidu.com在配置当中应该是www.baidu.com.(最后有一点),一般我们在浏览器里输入时会省略后面的点,而这也已经成为了习惯. 根域服 ...
- Android应用如何打包?
android app开发结束后,就需要对app进行打包.部署与发布了,那对于android初学者而言,如何对apk进行打包呢?今天小编就为大家分享一二,一起来看看吧~~ aapt package - ...
- VS debug 简记
近两日使用VS2013 Professional版本调试一个c源文件,过程中发现有几个bug,不知是IDE的问题还是我设置有问题,记在这里 1.下面的程序段A和B,区别只是for是否加花括号(标准C规 ...
- Spring----01. 入门知识,IoC/DI
1.spring两个最基本概念:依赖注入DI.面向切面AOP 2.spring通过上下文Application Context装配bean,实现方式的区别是如何加载它们的配置信息, ClassPath ...