http://poj.org/problem?id=1185

一次考虑两行,比一行略为复杂。sta保存每种状态炮兵位置,sum保存每种状态当行炮兵总数,a保存地形,dp[i][j][k]表示到第i行当前行j状态上一行k状态的最大炮兵数。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
//int main()
//{
// int num = 0;
// for(int i = 0;i <= (1<<10);i++)
// {
// if(i & (i<<2) || i & (i<<1)) continue;
// num++;
// }
// printf("%d",num);
//} int dp[][][],a[] = {},n,m,sta[],sum[] = {}; int main()
{
memset(dp,-,sizeof(dp));
scanf("%d%d",&n,&m);
getchar();
if(n == && m == )
{
printf("0\n");
return ;
}
for(int i = ;i < n;i++)
{
char temp[];
gets(temp);
for(int j = ;j < m;j++)
{
if(temp[j] == 'H') a[i] |= (<<j);
}
}
// for(int i = 0;i < n;i++) printf("%d\n",a[i]);
int cnt = ;
for(int i = ;i < (<<m);i++)
{
if(i & (i<<)) continue;
if(i & (i<<)) continue;
sta[cnt] = i;
int temp = i;
while(temp)
{
sum[cnt] += temp%;
temp /= ;
}
cnt++;
}
// for(int i = 0;i < cnt;i++) printf("%d %d\n",sta[i],sum[i]);
for(int i = ;i < cnt;i++)
{
if(a[] & sta[i]) continue;
dp[][i][] = sum[i];
}
// for(int i = 0;i < cnt;i++) printf("%d\n",dp[0][i][0]);
for(int i = ;i < cnt;i++)
{
if(a[] & sta[i]) continue;
for(int j = ;j < cnt;j++)
{
if(sta[i] & sta[j]) continue;
dp[][i][j] = max(dp[][i][j],dp[][j][]+sum[i]);
}
}
for(int i = ;i < n;i++)
{
for(int j = ;j < cnt;j++)
{
if(a[i] & sta[j]) continue;
for(int k = ;k < cnt;k++)
{
if(sta[j] & sta[k]) continue;
for(int l = ;l < cnt;l++)
{
if(sta[j] & sta[l]) continue;
if(dp[i-][k][l] == -) continue;
dp[i][j][k] = max(dp[i][j][k],dp[i-][k][l]+sum[j]);
}
}
}
}
// for(int i = 0;i < cnt;i++)
// {
// for(int j = 0;j < cnt;j++) printf("%d ",dp[n-1][i][j]);
// printf("\n");
// }
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 ;
}

POJ_1185_状态压缩dp的更多相关文章

  1. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  2. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  3. [知识点]状态压缩DP

    // 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...

  4. HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP

    题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...

  5. DP大作战—状态压缩dp

    题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...

  6. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  7. BZOJ-1226 学校食堂Dining 状态压缩DP

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...

  8. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  9. HDU 1074 (状态压缩DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...

随机推荐

  1. Linux-Cacti监控{Verson:1.2.8}

    首先需要一个LAMP平台 或LNMP平台 yum -y install httpd mariadb php mariadb-server mariadb-devel zlib freetype lib ...

  2. C# 启动 a Python Web Server with Flask

    概览 最近有个需求是通过c#代码来启动python 脚本.嘿~嘿!!! 突发奇想~~既然可以启动python脚本,那也能启动flask,于是开始着手操作. 先看一波gif图 通过打开控制台启动flas ...

  3. 简单快速破解IDEA

    ====================================2019.09.16更新==================================== 可以直接去掉第三步,直接在激活 ...

  4. Winform PPT切换图片效果

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. ASP.Net MVC 引用动态 js 脚本

    希望可以动态生成 js  发送给客户端使用. layout页引用: <script type="text/javascript" src="@Url.Action( ...

  6. MySQL UTF-8 常用字符排序规则

    排序规则 解释 utf8_general_ci 不区分大小写 utf8_general_cs 区分大小写 utf8_bin 区分大小写,字符串每个字符串用二进制数据编译存储,且支持存储二进制数据

  7. 2018 CCPC 网络赛

    The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed ...

  8. Linux环境下Mysql开启远程访问权限

    如何通过Window的数据库可视化工具远程连接装在Linux上的Mysql呢?可以按照以下步骤逐一确认! 检查监听端口是否存在 netstat -ntlp |grep mysql 检查Mysql配置配 ...

  9. python认识及环境变量

    什么是python? python是一种脚本语言,是高级语言.计算机只能识别机器语言,在机器语言上是汇编语言,再往上是高级语言.高级语言的基础是C语言. python语言较为简单,易入门. pytho ...

  10. restframework 分页组件、响应器

    一.分页组件 1.PageNumberPagination a.全局配置 导入模块 from rest_framework.pagination import PageNumberPagination ...