poj 2836 Rectangular Covering (状态压缩dp~)
来源:互联网 发布:微信营销数据分析 编辑:程序博客网 时间:2024/05/21 15:00
刚看到题目时真没想到是状态压缩,当然我什么想法也没有,果然是我太菜了。。。。后来看了题解还是觉挺清楚的。。。
有个坑!!!
算面积那里,注意矩形边长万一小于1,是需要取整为1的。不然会WA。
#include <stdio.h>#include <string.h>#include <cmath>#include <iostream>#include <vector>using namespace std;#define MAX_N 20#define INF 0x3f3f3fint x[MAX_N], y[MAX_N];struct Rectangle { int cover; //点集 int area; //面积 Rectangle(int c, int a) { cover = c; area = a; } //第几位表示第几个点 void addpoint(int c) { cover |= (1 << c); }};//点k在不在i和j组成的矩形中bool is_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 dp[1 << 16];int main(void) { int n; while (scanf("%d", &n) == 1 && n) { int xx, yy; for (int i = 0; i < n; i++) { scanf("%d%d", &xx, &yy); x[i] = xx; y[i] = yy; } vector<Rectangle> V; //对每个矩形进行初始化 for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { Rectangle r((1 << i) | (1 << j), max((int)abs(x[i] - x[j]), 1) * max(((int)abs(y[i] - y[j])), 1)); for (int k = 0; k < n; k++) { if (is_in(i, j, k)) r.addpoint(k); } V.push_back(r); } } // dp[i]的含义是包含i个矩形的最小面积 memset(dp, INF, sizeof(dp)); dp[0] = 0; for (size_t i = 0; i < V.size(); i++) { for (int state = 0; state < (1 << n); state++) { int newstate = state | V[i].cover; //此条件限制了只能从第0个开始dp if (dp[state] == INF) continue; if (newstate == state) continue; dp[newstate] = min(dp[newstate], dp[state] + V[i].area); } } printf("%d\n", dp[(1 << n) - 1]); } return 0;}
阅读全文
0 0
- POJ 2836 Rectangular Covering 状态压缩DP
- POJ - 2836 Rectangular Covering(状态压缩DP)
- poj - 2836 - Rectangular Covering(状态压缩dp)
- poj 2836 Rectangular Covering (状态压缩dp~)
- POJ 2836 Rectangular Covering 状态压缩DP 几何
- poj 2836 Rectangular Covering(状压DP)
- [POJ 2836] Rectangular Covering (状压DP)
- poj 2836 Rectangular Covering (状压dp)
- Poj 2836 Rectangular Covering(状压DP)
- poj 2836 Rectangular Covering(状压dp)
- POJ 2836 Rectangular Covering -状压DP+枚举
- POJ 2836 Rectangular Covering(状压dp)
- POJ-2836-Rectangular Covering
- POJ 2836 Rectangular Covering
- POJ 2836Rectangular Covering
- poj 2836 Rectangular Covering
- POJ2836-Rectangular Covering-状态dp
- 文章标题 POJ : Rectangular Covering(状压DP)
- wifi相关研究团队
- 走进webpack—我的webpack学习记录(1)
- docker报错-->Error response from daemon: Get xxx: unauthorized: incorrect username or password
- Hexo搭建博客并且部署到github(mac版本)
- 继承练习 :开发一个系统时 需要对员工进行建模 员工包含3个属性 姓名 工号 工资 功能 work
- poj 2836 Rectangular Covering (状态压缩dp~)
- ssh登录阿里云服务器Host key verification failed.
- PAT乙级(Basic Level)练习题 斐波那契凤尾
- 排序-插入类排序
- 11/20/2017
- 百度地图开发之一(创建百度地图)
- Shell语言
- 多线程基础01
- [算法分析与设计] leetcode 每周一题:Longest Substring Without Repeating Characters