bzoj2755【SCOI2012】喵星人的入侵
输入格式
第一行为三个整数n,m,K,分别表示地图的长和宽,以及最多能放置的炮塔数量。
接下来的n行,每行包含m个字符,‘#’表示地图上原有的障碍,‘.’表示该处为空地,
数据保证在原地图上存在S到T的路径。
输出格式
输出在合理布阵下,喵星人采取最优策略后,会受到的最大伤害。
注意必须保证在布阵结束后喵星人仍然可以沿一条或以上的路径从起点S到达终点T,
否则他们组织更大规模的侵略。
提示
【数据范围】
对于30%的数据,保证:
1<=N,M<=6
对于100%的数据,保证:
1<=N<=6,1<=M<=20,1<=K<=15,且从S到T的路径必定存在。
题解:
- 由于可以无限放置障碍,所以最后一定只会有一条路径;
- 插头$dp$求出路径即可;
- 注意和普通路径不同,路径不能组成四连通块;
#include<bits/stdc++.h>
#define il inline
#define rg register
using namespace std;
const int N=,M=,sz=1e5;
int n,m,K,c1[N],c2[N],cur,ans;
char s[M][M];
struct HASH{
int o,hd[sz],v[sz],w[sz],nt[sz];
il void init(){for(int i=;i<=o;++i)hd[v[i]%sz]=,v[i]=w[i]=nt[i]=;o=;}
il void upd(int x,int y){
for(rg int i=hd[x%sz];i;i=nt[i])if(v[i]==x){
if(w[i]<y)w[i]=y;
return;
}
nt[++o]=hd[x%sz],hd[x%sz]=o,v[o]=x,w[o]=y;
}
}f[][M];
il void upd(int&x,int y){if(x<y)x=y;}
il void decode(int x){
for(rg int i=;i<=m;++i)c1[i]=x&,x>>=;
for(rg int i=;i<=m;++i)c2[i]=x&,x>>=;
}
il int encode(){
int x=;
for(rg int i=m;~i;--i)x=(x<<)^c2[i];
for(rg int i=m;~i;--i)x=(x<<)^c1[i];
return x;
}
il int le(int x){
for(rg int i=x,y=;~i;--i)if(c1[i]&&c1[i]!=){
y+=(c1[i]&)?:-;
if(!y)return i;
}return ;
}
il int ri(int x){
for(rg int i=x,y=;i<=m;++i)if(c1[i]&&c1[i]!=){
y+=(c1[i]&)?:-;
if(!y)return i;
}return ;
}
il int cal1(int x){
int l=max(x-,),r=min(x+,m),re=;
for(rg int i=l;i<=r;++i)if(c2[i]==)re++;
return re;
}
il int cal2(int x){
int l=max(x-,),r=min(x+,m),re=;
for(rg int i=l;i<=r;++i)if(c2[i]==)re++;
return re;
}
il bool check(int j){
for(rg int i=;i<=m;++i)if(i!=j&&i!=j+&&c1[i])return false;
return true;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
#endif
scanf("%d%d%d",&n,&m,&K);
for(rg int i=;i<n;++i)scanf("%s",s[i]);
if(n<m){
for(rg int i=;i<n;++i)
for(rg int j=i+;j<m;++j){
swap(s[i][j],s[j][i]);
}
swap(n,m);
}
f[cur=][].upd(,);
for(rg int i=;i<n;++i)
for(rg int j=;j<m;++j){
for(rg int k=;k<=K;++k){
for(rg int l=;l<=f[cur][k].o;++l){
int w=f[cur][k].w[l];
decode(f[cur][k].v[l]);
if(!j){
if(c1[m])continue;
for(rg int i=m;i;--i)c1[i]=c1[i-],c2[i]=c2[i-];
c1[]=c2[]=;
}
/*
{
printf("%d %d %d:\n",i,j,k);
for(int i=0;i<=m;++i)printf("%d ",c1[i]);
puts("");
for(int i=0;i<=m;++i)printf("%d ",c2[i]);
puts("");
printf("%d\n",w);
printf("#\n");
}*/ int &p=c1[j],&q=c1[j+],&r=c2[j],w1=w+cal1(j),w2=w+cal2(j);
int t1=j&&(c2[j-]&),t2=j!=m&&(c2[j+]&);
if(s[i][j]=='#'){
if(p||q)continue;
r=,f[cur^][k].upd(encode(),w);
}else if(!p&&!q){
if(s[i][j]=='.'){
p=,q=;
r=,f[cur^][k].upd(encode(),w);
if(k<K)r=,f[cur^][k+].upd(encode(),w1);
}
if(t1||t2)continue;
if(s[i][j]=='S'||s[i][j]=='T'){
p=,q=,r=,f[cur^][k].upd(encode(),w2);
p=,q=,r=,f[cur^][k].upd(encode(),w2);
}else p=,q=,r=,f[cur^][k].upd(encode(),w2);
}else if(!p||!q){
if(t1&&t2)continue;
if(s[i][j]=='S'||s[i][j]=='T'){
if(p+q!=){
if(p+q==)c1[ri(j)]=;else c1[le(j+)]=;
p=q=,r=,f[cur^][k].upd(encode(),w2);
}
else if(check(j))p=,q=,r=,f[cur^][k].upd(encode(),w2);
}else{
r=,swap(p,q),f[cur^][k].upd(encode(),w2);
r=,swap(p,q),f[cur^][k].upd(encode(),w2);
}
}else{
if(p==&&q==){
p=q=,r=,f[cur^][k].upd(encode(),w2);
}else if(p==||q==){
if(p+q-==)c1[ri(j)]=;
else if(p+q-==)c1[le(j+)]=;
p=q=,r=,f[cur^][k].upd(encode(),w2);
}else {
if(p==&&q==)continue;
if(p==q){
if(p==)c1[ri(j+)]=;
else c1[le(j)]=;
}
p=q=,r=,f[cur^][k].upd(encode(),w2);
}
}
}
f[cur][k].init();
}
cur^=;
}
for(int i=;i<=K;++i)
for(int j=;j<=f[cur][i].o;++j){
decode(f[cur][i].v[j]);
if(check(m+))upd(ans,f[cur][i].w[j]);
}
printf("%d\n",ans);
return ;
}
bzoj2755【SCOI2012】喵星人的入侵的更多相关文章
- 洛谷 P2337 【[SCOI2012]喵星人的入侵】
这几天一直在刷插头Dp,写了几道入门题后,觉得还比较水,直到我发现了这一题.... 题目大意:给你一个n*m的地图,有些是空地,有些是障碍,还有两个是ST,在给你一个L,代表可以放L个炮台,你要在空地 ...
- 插头dp小结
插头dp: \(A:\)插头dp是什么? \(B:\)一种基于连通性状态压缩的动态规划问题 \(A:\)请问有什么应用呢? \(B:\)各种网格覆盖问题,范围允许状压解决,常用于计算方案数与联通块权值 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ_2754__[SCOI2012]_喵星球上的点名_(暴力+后缀数组)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=2754 给出n个姓名串和m个点名串.求每个点名串在多少人的姓名中出现过(在名中出现或在姓中出现, ...
- BZOJ 2754([SCOI2012]喵喵叫的星球-统计序列的后缀阵列中子序列出现次数)
2754: [SCOI2012]喵喵叫的星球 Time Limit: 20 Sec Memory Limit: 128 MB Submit: 805 Solved: 380 [id=2754&qu ...
- BZOJ 2754: [SCOI2012]喵星球上的点名
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 649 Solved: 305[Submit][Sta ...
- BZOJ2754: [SCOI2012]喵星球上的点名
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 680 Solved: 314[Submit][Sta ...
- BZOJ 2754: [SCOI2012]喵星球上的点名 [后缀数组+暴力]
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1906 Solved: 839[Submit][St ...
- BZOJ 2754: [SCOI2012]喵星球上的点名 [AC自动机+map+暴力]
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1902 Solved: 837[Submit][St ...
随机推荐
- KClient——kafka消息中间件源码解读
目录 kclient消息中间件 kclient-processor top.ninwoo.kclient.app.KClientApplication top.ninwoo.kclient.app.K ...
- python所遇到的坑
我是在ubuntu中,自带的有python2,python3有安装了anaconda套件,所以python的版本很多,曾经想删除过不用的python. 先执行 sudo apt remove pyth ...
- scrapy有用的(代理,user-agent,随机延迟等)
代理 方法一(待测试) 见scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware import os # 设置相应的代理用户名密码,主机和 ...
- Beta发布--PSP DAILY软件功能说明书2.0
一.开发背景 你在完成了一周的软件工程作业后,需要提交一个PSP图表,里面有4项,如下所示: 1.本周PSP表格,包含每项任务的开始.中断.结束.最终时间,格式如下: 2.本周进度条,包含从开始到现在 ...
- iOS开发学习-如何优化tableview的使用
1.复用单元格 2.单元格中的视图尽量都使用不透明的,单元格中尽量少使用动画 3.图片加载使用异步加载 4.滑动时不加载图片,停止滑动时开始加载 5.单元格中的内容可以在自定义cell类中的drawR ...
- web02-welcomeyou
新建web项目web02-welcomeyou, 修改index.jsp为 <body> This is my JSP page. <br> <form action=& ...
- 炸弹人 之 N A B C D
团队开发之个人——NABCD理解 项目名称:炸弹人(app)N(need): 随着移动终端的发展,各类软件的需求必然会有长期的需求,而游戏类软件是不同年龄阶段的人共同的需求,我们将要开发的这款游 ...
- MaxAlertView 强大的弹框试图
[链接]https://github.com/MrJalen/MaxAlertView MaxAlertView ) { [MaxAlertView showAlertWithTitle:@" ...
- Internet History, Technology and Security (Week 1)
Week 1 History: Dawn of Electronic Computing Welcome to Week 1! This week, we'll be covering the ear ...
- Art & Material
Art(Android runtime)模式伴随Android 4.4发布.相对于Dalvik模式来说,Art模式改善了Android程序的性能. Material Design伴随Android 5 ...