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),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- axure注册码
ahjesus Axure RP 7.0注册码 用户名:axureuser 序列号:8wFfIX7a8hHq6yAy6T8zCz5R0NBKeVxo9IKu+kgKh79FL6IyPD6lK7G6+t ...
- host文件的作用和介绍
在Window系统中有个Hosts文件(没有后缀名)在Windows98系统下该文件在Windows目录,在Windows2000/XP系统中位于C:\Winnt\System32\Drivers\E ...
- 反编译.o到.cpp
反编译.o到.cpp 现在有很多反编译是对Java的,而.cpp的很少 因为不同的平台.cpp生成的.o是不一样的,但是Java因为有虚拟机的中间作用,生成的.o在不同平台是一样的 反编译的机理 (通 ...
- C语言 SDK编程之通用控件的使用--ListView
一.ListView控件属于通用控件CONTROL中的一种,在SDK编程方式时要使用通用控件 必须包含comctl32.dll,所以代码中要有头文件: commctrl.h 导入库:comctl32. ...
- DataGridView显示时间格式
默认显示时间不显示秒yyyy-MM-dd HH:mm dataGridView.Columns["日期时间字段"].DefaultCellStyle.Format = " ...
- C# 与C++的数据转换
一.类型转化 下面重点罗列下常用的类型转化. C++类型 C#类型 备注说明 Int Int16.Int32 没有悬念,直接转化 Uint UInt16.Uint32.int 在程序中,不太清楚是,就 ...
- google map 点与点画线
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- php连接ftp
PHP连接ftp,发现一个很好用的类库phpseclib.英文原文 Connecting to SFTP with PHP If you need to connect to SFTP using P ...
- TImage 的一些操作
//给 image上写数字. Image1.Picture.Bitmap.Height:= Image1.Height; Image1.Picture.Bitmap.Width:= Image1.Wi ...
- python装饰器总结
一.装饰器是什么 python的装饰器本质上是一个Python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象.简单的说装饰器就是一个用来返回函数的函数 ...