POJ1185:火炮(减少国家)
Description

假设在地图中的灰色所标识的平原上部署一支炮兵部队,则图中的黑色的网格表示它可以攻击到的区域:沿横向左右各两格,沿纵向上下各两格。图上其他白色网格均攻击不到。
从图上可见炮兵的攻击范围不受地形的影响。
如今,将军们规划怎样部署炮兵部队,在防止误伤的前提下(保证不论什么两支炮兵部队之间不能互相攻击,即不论什么一支炮兵部队都不在其它支炮兵部队的攻击范围内),在整个地图区域内最多可以摆放多少我军的炮兵部队。
Input
接下来的N行,每一行含有连续的M个字符('P'或者'H')。中间没有空格。按顺序表示地图中每一行的数据。N <= 100;M <= 10。
Output
Sample Input
5 4
PHPP
PPHH
PPPP
PHPP
PHHP
Sample Output
6
与HDU4539基本上一样的题目,仅仅是在推断情况上有些不同而已
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int n,m;
char map[105][15];
int mat[105][15];
int now[1<<10],pre[1<<10],prepre[1<<10];
int l_now,l_pre,l_prepre;
int dp[1<<10][1<<10],tem[1<<10][1<<10],tt[1<<10]; void dfs(int id,int k,int p,int sum)
{
if(k>=m)
{
now[++l_now] = p;
tt[l_now] = sum;
return;
}
if(k>=2 && mat[id][k] && !(p&(1<<(k-2))) && !(p&(1<<(k-1))))
dfs(id,k+1,p|(1<<k),sum+1);
else if(k==1 && mat[id][k] && !(p&(1<<(k-1))))
dfs(id,k+1,p|(1<<k),sum+1);
else if(k == 0 && mat[id][k])
dfs(id,k+1,p|(1<<k),sum+1);
dfs(id,k+1,p,sum);
} void solve()
{
int i,j,k,t;
tem[1][1] = pre[1] = prepre[1] = 0;
l_pre = l_prepre = 1;
for(k = 0; k<n; k++)
{
l_now = 0;
dfs(k,0,0,0);
for(i = 1; i<=l_now; i++)
for(j = 1; j<=l_pre; j++)
dp[i][j] = 0;
for(i = 1; i<=l_now; i++)
for(j = 1; j<=l_pre; j++)
for(t = 1; t<=l_prepre; t++)
{
if(now[i] & prepre[t]) continue;
if(now[i] & pre[j]) continue;
if(pre[j] & prepre[t]) continue;
dp[i][j] = max(dp[i][j],tem[j][t]+tt[i]);
}
for(i = 1; i<=l_now; i++)
for(j = 1; j<=l_pre; j++)
tem[i][j] = dp[i][j];
for(i = 1; i<=l_pre; i++)
prepre[i] = pre[i];
for(i = 1; i<=l_now; i++)
pre[i] = now[i];
l_prepre = l_pre;
l_pre = l_now;
}
} int main()
{
int i,j,ans;
while(~scanf("%d%d",&n,&m))
{
for(i = 0; i<n; i++)
{
scanf("%s",map[i]);
for(j = 0; j<m; j++)
{
if(map[i][j] == 'P')
mat[i][j] = 1;
else
mat[i][j] = 0;
}
}
solve();
ans = 0;
for(i = 1; i<=l_pre; i++)
for(j = 1; j<=l_prepre; j++)
ans = max(ans,tem[i][j]);
printf("%d\n",ans);
} return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
POJ1185:火炮(减少国家)的更多相关文章
- poj 1185 火炮 (减少国家DP)
火炮 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19690 Accepted: 7602 Description 司 ...
- hdu 4778 Rabbit Kingdom(减少国家)
题目链接:hdu 4778 Rabbit Kingdom 题目大意:Alice和Bob玩游戏,有一个炉子.能够将S个同样颜色的宝石换成一个魔法石.如今有B个包,每一个包里有若干个宝石,给出宝石的颜色. ...
- 可能性dp+减少国家HDU4336
Card Collector Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- poj - 1170 - Shopping Offers(减少国家dp)
意甲冠军:b(0 <= b <= 5)商品的种类,每个人都有一个标签c(1 <= c <= 999),有需要购买若干k(1 <= k <=5),有一个单价p(1 & ...
- [ACM] hdu 5045 Contest (减少国家Dp)
Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP
意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...
- Chapter06-Phylogenetic Trees Inherited(POJ 2414)(减少国家DP)
Phylogenetic Trees Inherited Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 480 Accepted ...
- POJ 2411 Mondriaan's Dream (dp + 减少国家)
链接:http://poj.org/problem?id=2411 题意:题目描写叙述:用1*2 的矩形通过组合拼成大矩形.求拼成指定的大矩形有几种拼法. 參考博客:http://blog.csdn. ...
随机推荐
- href=“file://” doesn't work
Local Explorer 2016.6.21.0 CRX for Chrome or Chromium https://www.crx4chrome.com/extensions/eokekhgp ...
- 手把手生成决策树(dicision tree)
手把手生成决策树(dicision tree) 标签: Python 机器学习 主要參考资料: Peter HARRINGTON.机器学习实战[M].李锐,李鹏,曲亚东,王斌译.北京:人民邮电出版社, ...
- 证明的手段 —— 不失一般性的(WLOG)
不失一般性是数学中一个常见的表达.不失一般性(Without loss of generality,缩写:WLOG.WOLOG 或 w.l.o.g.)是数学中一个常见的表达. 如果给不相等的两数,a, ...
- WD-保修验证(WCC7K4ARTDF1)
https://support.wdc.com/warranty/warrantystatus.aspx?lang=cn WCC7K4ARTDF1 有限保修期限内 WD40EFRX WD Red 09 ...
- svn pre commit
windows下的必须要用.bat文件,pre-commit.bat ================================================== @echo off set ...
- 【codeforces 758B】Blown Garland
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [NativeScript] Style NativeScript views using the default core theme
The default core theme comes preinstalled and ready to go with every new project. Learn how to use s ...
- java开发中的那些事(5)--------一点经历,败给2分钟的2个小时
特意记下这个经历,这个让我感慨万千又斗志昂扬的一次经历,这是经验,也是生活. 故事的始末是这种,先给大家上几句代码,如今身在家中,仅仅能凭记忆敲打几行,大致意思倒不会错: {field:'code', ...
- [Ramda] Create an Array From a Seed Value with Ramda's unfold
In this lesson we'll look at how you can use Ramda's unfold function to generate a list of values ba ...
- 找不到头文件xxxxx.h file not found
项目里有该文件,但是还是显示找不到.或者是cocopods打开的项目. 原因:.h文件路径找不到.具体找不到的原因有很多种. 1.一般会设置 IOS引用三方framewrok的头文件出现'xxxxx/ ...