hdu 4739(状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4739
思路:状态压缩。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std; struct Point{
int x,y;
}point[]; int dp[(<<)+];
int n; int cmp(const Point &p,const Point &q)
{
if(p.y==q.y){
return p.x<q.x;
}
return p.y<q.y;
} bool Judge(int i,int j,int k,int l)
{
if(point[i].x==point[j].x&&point[i].y==point[j].y)return false;
if(point[i].y!=point[j].y||point[i].x!=point[k].x||point[j].x!=point[l].x||point[k].y!=point[l].y)
return false;
if(abs(point[i].x-point[j].x)!=abs(point[i].y-point[k].y))
return false;
return true;
} vector<int>g[];
int main()
{
while(~scanf("%d",&n)){
if(n==-)break;
for(int i=;i<n;i++)scanf("%d%d",&point[i].x,&point[i].y);
sort(point,point+n,cmp);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)g[i].clear();
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
for(int k=j+;k<n;k++){
for(int l=k+;l<n;l++){
if(Judge(i,j,k,l)){
int state=;
state|=(<<i);
state|=(<<j);
state|=(<<k);
state|=(<<l);
g[i].push_back(state);
}
}
}
}
}
for(int state=;state<(<<n);state++){
for(int i=;i<n;i++){
if(state&(<<i)){
for(int j=;j<g[i].size();j++){
int S=g[i][j];
if((S|state)==state)dp[state]=max(dp[state],dp[state^S]+);
}
}
}
}
printf("%d\n",dp[(<<n)-]);
}
return ;
}
hdu 4739(状态压缩)的更多相关文章
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
- HDU 3341 状态压缩DP+AC自动机
题目大意: 调整基因的顺序,希望使得最后得到的基因包含有最多的匹配串基因,使得所能达到的智商最高 这里很明显要用状态压缩当前AC自动机上点使用了基因的情况所能达到的最优状态 我最开始对于状态的保存是, ...
- hdu 2167(状态压缩基础题)
题意:给你一个矩阵,让你在矩阵中找一些元素使它们加起来和最大,但是当你使用某一个元素时,那么这个元素周围的其它八个元素都不能取! 分析:这是一道比较基础的状态压缩题,也是我做的第三道状态压缩的题,但是 ...
- hdu 1565(状态压缩基础题)
题意:容易理解. 分析:这是我做的状态压缩第二题,一开始超内存了,因为数组开大了,后来超时了,因为能够成立的状态就那么多,所以你应该先把它抽出来!!总的来说还是比较简单的!! 代码实现: #inclu ...
- HDU 2553 状态压缩
N皇后问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 3006(状态压缩)
The Number of set Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 2489(状态压缩+最小生成树)
Minimal Ratio Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 4033 状态压缩枚举
/* 看别人的的思路 搜索搜不出来我太挫了 状态压缩枚举+好的位置 */ #include<stdio.h> #include<string.h> #define N 20 i ...
- HDU 4856 (状态压缩DP+TSP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4856 题目大意:有一个迷宫.迷宫里有些隧道,每个隧道有起点和终点,在隧道里不耗时.出隧道就耗时,你的 ...
随机推荐
- BerkeleyDB java的简单使用
关于BerkeleyDB的有点和优点,列在以下 JE offers the following major features: Large database support. JE databases ...
- JAVA实现zip压缩需要注意的问题
近来对院社二维码平台进行2.0升级改造.于昨日踩到一个巨坑.特此记录... 需求源于院社编辑在批量下载二维码的时候,系统后台需要对所要下载的二维码进行重命名和zip打包压缩. 系统测试的时候发现:首次 ...
- mybatis xml和dao扫描写法
第一种:接口和xml不在同一个目录,需要在sqlSessionFactoryBean中额外 指定xml的路径: <!-- myBatis文件 --> <bean id="s ...
- 【LeetCode】162. Find Peak Element (3 solutions)
Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...
- JS 校验,检测,验证,判断函数集合
http://jc-dreaming.iteye.com/blog/754690 /** *判断对象是否为空 *Check whether string s is empty. */ funct ...
- C#:DataGridView控件操作
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- MS SQL server中的isnull函数
一.ISNULL语法格式 ISNULL ( check_expression , replacement_value ) 二.参数简介 check_expression:将被检查是否为 NULL的表达 ...
- Hp && Dell服务器硬件监控
HP 安装HP工具: yum install hpssacli 1 查看控制器状态 raid卡型号等hpssacli ctrl all show status 2 查看硬盘类型.大小 raid级别.状 ...
- $scope绑定事件之$on方法和$emit,$broadcast
function DemoCtrl($scope){ $scope.count = 0; $scope.$on('myevent',function(){ $scope.count++; }) } 视 ...
- 远程登录linux上的mysql数据库
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1; 讲root账户,的HOST设置为%,允许所有公网IP访问. flush priv ...