HDU4539+状态压缩DP
/*
题意:n行m列的矩阵,1表示可以放东西,0表示不可以。曼哈顿距离为2的两个位置最多只能有一个位置放东西。
问最多放多少个东西。
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
using namespace std;
const int maxn = ;
const int maxm = ;
const int N = ;
int mat[ maxn ];
int dp[ maxn ][ N ][ N ];
int state[ N ];
int ones_state[ N ];
int Count_ones( int x ){
int cnt = ;
while( x ){
if( x& )
cnt++;
x>>=;
}
return cnt;
}
int init( int n,int m ){
memset( state,,sizeof( state ) );
memset( ones_state,,sizeof( state ) );
int M = <<m;
int cnt = ;
for( int i=;i<M;i++ ){
if( (i&(i<<))==&&(i&(i>>))== ){
state[ cnt ] = i;
ones_state[ cnt ] = Count_ones( i );
cnt++;
}
}
//printf("cnt=%d\n",cnt);最多169种状态!!
return cnt;
}
void DP( int cnt,int n,int m ){
memset( dp,-,sizeof( dp ) );
for( int i=;i<cnt;i++ ){
if( (state[i]&mat[])== )
dp[][i][] = ones_state[ i ];
}//初始化
for( int i=;i<n;i++ ){
for( int j=;j<cnt;j++ ){
if( (state[j]&mat[i])== ){
for( int k=;k<cnt;k++ ){
if( (state[j]&(state[k]<<))==&&(state[j]&(state[k]>>))== ){
for( int k2=;k2<cnt;k2++ ){
if( dp[i-][k][k2]==- ) continue;
if( (state[j]&state[k2])==&&(state[k]&(state[k2]>>))==&&(state[k]&(state[k2]<<))== )
dp[ i ][ j ][ k ] = max( dp[i][j][k],dp[i-][k][k2]+ones_state[j] );
}
}
}
}
}
}
}
int main(){
int n,m;
while( scanf("%d%d",&n,&m)== ){
int cnt = init( n,m );
memset( mat,,sizeof( mat ) );
int tmp;
for( int i=;i<n;i++ ){
for( int j=;j<m;j++ ){
scanf("%d",&tmp);
if( tmp== ){
mat[ i ] |= (<<j);
}
}
}
DP( cnt,n,m );
int ans = ;
for( int i=;i<cnt;i++ )
for( int j=;j<cnt;j++ )
ans = max( ans,dp[n-][i][j]);
printf("%d\n",ans);
}
return ;
}
HDU4539+状态压缩DP的更多相关文章
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- Cocoa框架中的内存分区
NSObject对象类实例为我们提供了两种分配内存的方式:alloc和allocWithZone:.alloc的实现也是为了调用allocWitZone:,它传入了一个默认的zone.所以明确的说,N ...
- 在SQL脚本中的注释引起的奇怪问题
在数据库安装包中,我们通过osql.exe这个工具来对相关的数据库脚本进行更新,昨天突然发现安装包报错了,说脚本错误,但我们将脚本拿到数据库查询分析器中执行,一切OK. 问题出在哪里呢? 通过使用os ...
- 随机森林之oob error 估计
摘要:在随机森林之Bagging法中可以发现Bootstrap每次约有1/3的样本不会出现在Bootstrap所采集的样本集合中,当然也就没有参加决策树的建立,那是不是意味着就没有用了呢,答案是否定的 ...
- DQL_数据查询语言
2014年11月21日 21:43:53 DQL 基础查询-- 注意要点:1.用户友善的标题 ...
- Tomcat & Nginx
http://cxshun.iteye.com/blog/1535188 反向代理方式实际上就是一台负责转发的代理 服务器,貌似充当了真正服务器的功能,但实际上并不是,代理服务器只是充当了转发的作用, ...
- ActiveMq+zookeeper+levelDB集群整合配置
ActiveMq+zookeeper+levelDB集群整合配置 环境:linux系统,jdk1.7 三台linux系统电脑.我这里使用一台window,分别远程3台linux电脑.三台电脑的ip分 ...
- IOS苹果购买PHP服务器端验证(订阅购买和一次性购买通用)
// 正式环境验证地址 $ios_verify_url = 'https://buy.itunes.apple.com/verifyReceipt'; // 测试环境验证地址 $ios_sandbox ...
- Beaglebone Back学习五(PWM测试)
PWM测试 参考链接 1 Enable PWM on BeagleBone with Device Tree overlays 2Using PWM on the Beaglebone Black 3 ...
- 关于帝国cms 列表页SEO优化的问题
一般列表页面中,我们都需要带分页信息区分当前页号,为区分第一页,和第一页后的其他所有分页页面.我们推荐的做法为:第一页显示正常的标题,从第二页开始便显示xxxxx-第2页-xxxx网.做法是.修改帝国 ...
- Hadoop 相关链接
Apache 软件下载 http://mirror.bit.edu.cn/apache/ 相关文档链接: Apache Hadoop 2.5.2 http://hadoop.apache.org ...