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 ...
随机推荐
- day04_07-三个函数的区别
<?php $link = @mysql_connect('localhost','root',''); mysql_query('use test',$link); mysql_query(' ...
- 新建git仓库--留
1.git config 配置配置息,查看配置信息
- ES6常用片段
promise: --在return里面: methods:{ getSellData(){ return axios.get('/api/seller').then((res=>{ retur ...
- Python的HttpClient实现
Python版本3.4(注意python的版本,python2和python3的写法不一样) 其实无非就是客户端的请求,所以python中这里使用的是urllib.request模块.主要注意的是he ...
- python XlsxWriter创建Excel 表格
文档(英文) https://xlsxwriter.readthedocs.io/index.html 常用模块说明(中文) https://blog.csdn.net/sinat_35930259/ ...
- linux备忘录-档案与文件系统的压缩与打包
知识点 文件扩展名与压缩解压缩工具 .Z -> compress程序压缩的档案 .gz -> gzip程序压缩的档案 .bz2 -> bzip2程序压缩的档案 .tar -> ...
- 锚点自适应 map area coords
最近做MOBILE的HTML5开发,人体图和页面一样,需要自适应不同的手机屏幕,蛋疼的是coords里面的标记是固定的,图片自适应后,锚点的标记就会产生空白区域,看了下https://github.c ...
- vue cli & vue 3.x
vue cli & vue 3.x https://cli.vuejs.org/dev-guide/ui-api.html#ui-api https://cli.vuejs.org/zh/gu ...
- hdu 3986 Harry Potter and the Final Battle (最短路径)
Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/6553 ...
- [codeforces] 449C Jzzhu and Apples
原题 质因数分解后贪心即可(最后贪2) #include<cstdio> #include<vector> #include<stack> #include< ...