POJ 2836 状压DP
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2727 | Accepted: 769 |
Description
n points are given on the Cartesian plane. Now you have to use some rectangles whose sides are parallel to the axes to cover them. Every point must be covered. And a point can be covered by several rectangles. Each rectangle should cover at least two points including those that fall on its border. Rectangles should have integral dimensions. Degenerate cases (rectangles with zero area) are not allowed. How will you choose the rectangles so as to minimize the total area of them?
Input
The input consists of several test cases. Each test cases begins with a line containing a single integer n (2 ≤ n ≤ 15). Each of the next n lines contains two integers x, y (−1,000 ≤ x, y ≤ 1,000) giving the coordinates of a point. It is assumed that no two points are the same as each other. A single zero follows the last test case.
Output
Output the minimum total area of rectangles on a separate line for each test case.
Sample Input
2
0 1
1 0
0
Sample Output
1
Hint
The total area is calculated by adding up the areas of rectangles used.
Source
题意:坐标平面上有n各点,用任意大小(非零)的矩形覆盖它们,每个矩形至少覆盖亮点,求最省的矩形的总面积。
解析:先预处理,将n个点两个两个组合构成多个矩形,然后将在矩形内部的点更新进矩形中。
然后就是dp的过程了:dp[0] = 0,初始时集合无点,面积为0,dp[nowS] = min ( dp[nowS], dp[s] + area),当前的点集的矩阵取,还是不取。
代码:
//#include "bits/stdc++.h"
#include "cstdio"
#include "map"
#include "set"
#include "cmath"
#include "queue"
#include "vector"
#include "string"
#include "cstring"
#include "time.h"
#include "iostream"
#include "stdlib.h"
#include "algorithm"
#define db double
#define ll long long
//#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define inf 0x3f3f3f3f
#define rep(i, x, y) for(int i=x;i<=y;i++)
const int N = 1e5 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const db eps = 1e-;
const db PI = acos(-1.0); using namespace std;
int n;
int x[],y[];
struct rec
{
int are,cov;
rec(){};
rec(int _are,int _cov) {are=_are,cov=_cov;}
void addP(int x) {cov|=(<<x);}//加点
};
int area(int i,int j)
{
return max(abs(x[i]-x[j]),)*max(abs(y[i]-y[j]),);
}
bool cal(int i,int j,int k){//判断第三点是否在前两点确定的矩形上
return (x[i]-x[k])*(x[j]-x[k])<=&&(y[i]-y[k])*(y[j]-y[k])<=;
}
vector<rec> e;
int f[N];
int main()
{
while(scanf("%d",&n)==&&n!=)
{
e.clear();
for(int i=;i<n;i++) ci(x[i]),ci(y[i]);
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
rec tmp(area(i,j),(<<i)|(<<j));
for(int k=;k<n;k++) if(cal(i,j,k)) tmp.addP(k);//合并点集
e.push_back(tmp);
}
}
memset(f,inf, sizeof(f));
f[]=;
for(int i=;i<e.size();i++){
for(int j=;j<(<<n);j++){//从0开始更新,每次加入点集
int S=j|e[i].cov;
if(f[j]!=inf) f[S]=min(f[S],f[j]+e[i].are);
}
}
pi(f[(<<n)-]);
}
return ;
}
POJ 2836 状压DP的更多相关文章
- POJ 3254 (状压DP) Corn Fields
基础的状压DP,因为是将状态压缩到一个整数中,所以会涉及到很多比较巧妙的位运算. 我们可以先把输入中每行的01压缩成一个整数. 判断一个状态是否有相邻1: 如果 x & (x << ...
- poj 1170状压dp
题目链接:https://vjudge.net/problem/POJ-1170 题意:输入n,表示有那种物品,接下来n行,每行a,b,c三个变量,a表示物品种类,b是物品数量,c代表物品的单价.接下 ...
- POJ 3254 状压DP
题目大意: 一个农民有一片n行m列 的农场 n和m 范围[1,12] 对于每一块土地 ,1代表可以种地,0代表不能种. 因为农夫要种草喂牛,牛吃草不能挨着,所以农夫种菜的每一块都不能有公共边. ...
- POJ 2411 状压DP经典
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16771 Accepted: 968 ...
- poj 3254 状压dp入门题
1.poj 3254 Corn Fields 状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...
- poj 1185(状压dp)
题目链接:http://poj.org/problem?id=1185 思路:状态压缩经典题目,dp[i][j][k]表示第i行状态为j,(i-1)行状态为k时最多可以放置的士兵个数,于是我们可以得到 ...
- poj 2923 状压dp+01背包
好牛b的思路 题意:一系列物品,用二辆车运送,求运送完所需的最小次数,两辆车必须一起走 解法为状态压缩DP+背包,本题的解题思路是先枚举选择若干个时的状态,总状态量为1<<n,判断这些状态 ...
- Islands and Bridges(POJ 2288状压dp)
题意:给你一个图和每个点的价值,边权值为连接两点权值的积,走哈密顿通路,若到达的点和上上个点相连则价值加三点乘积,求哈密顿通路的最大价值,和最大价值哈密顿通路的条数. 分析:开始看这个题很吓人,但想想 ...
- Hie with the Pie(POJ 3311状压dp)
题意:披萨店给n个地方送披萨,已知各地方(包括披萨店)之间花费的时间,求送完所有地方并回到店花费的最小时间 分析:状态好确定dp[i][j],i中1表示地方已送过,否则为0,j为当前状态最后一个送过的 ...
随机推荐
- System.Data.SqlClient.SqlException: 从 datetime2 数据类型到 datetime 数据类型的转换产生一个超出范围的值
System.Data.SqlClient.SqlException: 从 datetime2 数据类型到 datetime 数据类型的转换产生一个超出范围的值.解决办法是: 而这位大哥提出的解决办法 ...
- selenium profile remotedriver
使用 FirefoxProfile FirefoxProfilefp = new FirefoxProfile(); // set something on the profile... Desire ...
- VS2015卸载方法
VS2015卸载 直接再控制面板的卸载程序中找到 VS2015 的程序,邮件更改,安装程序会被打开,里面有三个选项包含卸载,点击卸载[记得在卸载前如果有打开过 VS 最好重启一下,重启后不要打开 VS ...
- MSSQL复制分发对异构数据库之间大容量数据分发造成异常
由于历史遗留的问题,现有的架构中存在采用MSSQL的复制分发功能,从Oracle发布数据到MSSQL. 关于这项发布的实现原理,官方表述如下: Oracle 事务发布是通过使用 SQL Server ...
- JavaScript 数组排序(从大到小,从小到大)
1.数组的从大到小排序 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...
- Torch.no_grad()影响MSE损失
相关描述 https://discuss.pytorch.org/t/torch-no-grad-affecting-outputs-loss/28595/3 今天在训练网络的时候,发现mseloss ...
- 前端高质量知识(二)-JS执行上下文(执行环境)详细图解Script
先随便放张图 我们在JS学习初期或者面试的时候常常会遇到考核变量提升的思考题.比如先来一个简单一点的. console.log(a); // 这里会打印出什么? var a = 20; PS: 变量提 ...
- Linux高性能server编程——定时器
版权声明:本文为博主原创文章.未经博主允许不得转载. https://blog.csdn.net/walkerkalr/article/details/36869913 定时器 服务器程序通常管 ...
- 怎样在 Ubuntu Linux 上安装 MySQL
本教程教你如何在基于 Ubuntu 的 Linux 发行版上安装 MySQL.对于首次使用的用户,你将会学习到如何验证你的安装和第一次怎样去连接 MySQL. -- Sergiu MySQL 是一个典 ...
- Spring MVC的一些学习笔记-入门配置和HttpMessageConverter
1.初步配置 [1]. 配置web.xml以及在web.xml中配置DispatcherServlet: <context-param> <param-name>context ...