HDU 2442
状态压缩DP , 和HDU2280极其相似
#include <cstdio>
#include <cstring>
#include <iostream> using namespace std;
const int N = ;
int dp[N][<<][<<] , n , m; //s 表示当前第i行的状态 , u表示上一行状态 , v表示上上行的状态 , cnt表示到当前位置时总共占据的空间
void dfs(int s , int u , int v , int cnt , int k , int i) //由右到左,访问到第i行的第k位数字
{
if(k >= m){
dp[i][u][s] = max(dp[i][u][s] , cnt);
return;
}
if(k > ){
if(!(s & (<<k)) && !(u & (<<k-)) && !(v & (<<k)))
dfs(s | (<<k) , u | (<<k-) , v | (<<k) , cnt + , k+ , i);
if(!(s & (<<k)) && !(u & (<<k)) && !(v & (<<k-)))
dfs(s | (<<k) , u | (<<k) , v | (<<k-) , cnt + , k+ , i);
}
if(k > ){
if(!(s & (<<k-)) && !(u & (<<k-)) && !(v & (<<k-)))
dfs(s | (<<k-) , u | (<<k-) , v | (<<k-) , cnt + , k+ , i);
if(!(s & (<<k-)) && !(u & (<<k-)))
dfs(s | (<<k-) , u | (<<k-) , v , cnt + , k+ , i);
if(!(s & (<<k)) && !(u & (<<k-)))
dfs(s | (<<k) , u | (<<k-) , v , cnt + , k+ , i);
}
dfs(s, u , v , cnt , k+ , i);
} void dfs2(int s , int u , int cnt , int k)
{
if(k >= m){
dp[][u][s] = max(dp[][u][s] , cnt);
return;
}
if(k > ){
if(!(s & (<<k-)) && !(u & (<<k-)))
dfs2(s | (<<k-) , u | (<<k-) , cnt + , k+);
if(!(s & (<<k)) && !(u & (<<k-)))
dfs2(s | (<<k) , u | (<<k-) , cnt + , k+);
}
dfs2(s,u,cnt,k+);
}
int main()
{
// freopen("a.in","rb",stdin);
while(~scanf("%d%d",&n,&m)){
memset(dp,-,sizeof(dp)); if(n == ){
puts("");
continue;
} dfs2(,,,); for(int i = ; i<=n ; i++){
for(int j = ; j < <<m; j++){
for(int t = ; t<<<m ; t++){
if(dp[i-][t][j]>=){
dfs(,j,t,dp[i-][t][j],,i);
}
}
}
} int ans = ;
for(int i = ; i<<<m ; i++){
for(int j = ; j<<<m ; j++)
{
//cout<<"in: "<<i<<" "<<" "<<j<<" "<<dp[n][i][j]<<endl;
ans = max(ans , dp[n][i][j]);
}
}
printf("%d\n" , ans);
}
return ;
}
HDU 2442的更多相关文章
- 状态压缩DP总结
POJ1185 炮兵部队问题: 在平原上才能放置炮兵,每个炮兵的上下左右2格之内都不能出现别的炮兵 可以考虑在当前行放置炮兵它的右侧和下侧绝对不会出现炮兵即可,左侧和上侧就能省去考虑 明显的状态压缩d ...
- HDU 1710 Binary Tree Traversals (二叉树遍历)
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDU——T 2444 The Accomodation of Students
http://acm.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- C#模版学习研究
原文链接1 原文链接2 using System; using System.Collections.Generic; using System.Text; using T = System.By ...
- IOS编译报错:objc-class-ref in AppDelegate.o之解决方案 Xcode7
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_QQApiInterface", referenced from ...
- ZOJ 3605Find the Marble(dp)
ZOJ 3605 大体意思就是 找出随机选了K个交换后 石子在第i个罐子里的概率最大 也就是可能的总数最大 这样就可以写出递推方程 dp[i][j][k] += dp[i-1][e][k]; (0&l ...
- MySQL DECIMAL数据类型
https://blog.csdn.net/zyz511919766/article/details/49335565
- 001原始编译全志r6平台tinav3.0.2系统
001原始编译全志r6平台tinav3.0.2系统 2018/6/8 11:32 版本:V1.0 开发板:R6 SDK:tina v3.0.2 1.01原始编译全志r16平台tinav3.0系统: r ...
- R in action读书笔记(5)-第七章:基本统计分析
7.1描述性统计分析 > vars<-c("mpg","hp","wt") > head(mtcars[vars]) ...
- wps 图片代码 复制 粘贴
<table><tr><td><img src="C:\Users\Administrator\Desktop\QQ截图20160921180946 ...
- cron on Centos
1. crond.service 2. configuration 2.0 format # Example of job definition: # .---------------- minute ...
- Android(java)学习笔记201:JNI之helloword案例(利用NDK工具)
1. 逻辑思路过程图: 2.下面通过一个HelloWorld案例来说明一下JNI利用NDK开发过程(步骤) 分析:我们在Win7系统下编译的C语言代码,我们知道C语言依赖操作系统,不能跨平台,所以我们 ...
- Laravel Mix编译前端资源
目前项目是使用的vue+laravel来写的,其中laravel和vue分别放了一个目录,但是这样有个问题,那就是vue需要经常更新,不然运行项目会经常出现各种问题,这里就看了看laravel的文档, ...