fzu1977
题解:
和前两题差不多
只不过变成了有些一定走,有些不一定
代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int HASH=;
const int STATE=;
int N,M,code[],maze[][],ch[],isend;
struct HASHMAP
{
int head[HASH],next[STATE],size;
ll state[STATE],f[STATE];
void init()
{
size=;
memset(head,-,sizeof(head));
}
void push(ll st,ll ans)
{
int h=st%HASH;
for (int i=head[h];i!=-;i=next[i])
if (state[i]==st)
{
f[i]+=ans;
return;
}
state[size]=st;
f[size]=ans;
next[size]=head[h];
head[h]=size++;
}
}hm[];
void decode(int *code,int m,ll st)
{
for (int i=m;i>=;i--)
{
code[i]=st&;
st>>=;
}
isend=st&;
}
ll encode(int *code,int m)
{
int cnt=;
memset(ch,-,sizeof(ch));
ch[]=;
ll st=isend;
for (int i=;i<=m;i++)
{
if (ch[code[i]]==-)ch[code[i]]=cnt++;
code[i]=ch[code[i]];
st<<=;
st|=code[i];
}
return st;
}
void shift(int *code,int m)
{
for (int i=m;i>;i--)code[i]=code[i-];
code[]=;
} void dpblank(int i,int j,int cur)
{
int left,up;
for (int k=;k<hm[cur].size;k++)
{
decode(code,M,hm[cur].state[k]);
left=code[j-];
up=code[j];
if (isend)
{
if (left||up||maze[i][j]==)continue;
code[j-]=code[j]=;
if (j==M)shift(code,M);
hm[cur^].push(encode(code,M),hm[cur].f[k]);
continue;
}
if (left&&up)
{
if (left==up)
{
code[j-]=code[j]=;
isend=;
if(j==M)shift(code,M);
hm[cur^].push(encode(code,M),hm[cur].f[k]);
}
else
{
code[j-]=code[j]=;
for (int t=;t<=M;t++)
if (code[t]==up)code[t]=left;
if (j==M)shift(code,M);
hm[cur^].push(encode(code,M),hm[cur].f[k]);
}
}
else if ((left&&(!up))||((!left)&&up))
{
int t;
if (left)t=left;
else t=up;
if (maze[i][j+])
{
code[j-]=;
code[j]=t;
hm[cur^].push(encode(code,M),hm[cur].f[k]);
}
if (maze[i+][j])
{
code[j-]=t;
code[j]=;
if (j==M)shift(code,M);
hm[cur^].push(encode(code,M),hm[cur].f[k]);
}
}
else
{
if (maze[i][j+]&&maze[i+][j])
{
code[j-]=code[j]=;
hm[cur^].push(encode(code,M),hm[cur].f[k]);
}
if (maze[i][j]==)
{
code[j-]=code[j]=;
if (j==M)shift(code,M);
hm[cur^].push(encode(code,M),hm[cur].f[k]);
}
}
}
}
void dpblock(int i,int j,int cur)
{
for (int k=;k<hm[cur].size;k++)
{
decode(code,M,hm[cur].state[k]);
code[j-]=code[j]=;
if (j==M)shift(code,M);
hm[cur^].push(encode(code,M),hm[cur].f[k]);
}
}
char str[];
void init()
{
scanf("%d%d",&N,&M);
memset(maze,,sizeof(maze));
for (int i=;i<=N;i++)
{
scanf("%s",&str);
for (int j=;j<=M;j++)
{
if (str[j-]=='*')maze[i][j]=;
else if (str[j-]=='O')maze[i][j]=;
}
}
}
void solve()
{
int cur=;
hm[cur].init();
hm[cur].push(,);
for (int i=;i<=N;i++)
for (int j=;j<=M;j++)
{
hm[cur^].init();
if(maze[i][j])dpblank(i,j,cur);
else dpblock(i,j,cur);
cur^=;
}
ll ans=;
for (int i=;i<hm[cur].size;i++)ans+=hm[cur].f[i];
printf("%I64d\n",ans);
}
int main()
{
int T,iCase=;
scanf("%d",&T);
while (T--)
{
iCase++;
printf("Case %d: ",iCase);
init();
solve();
}
return ;
}
fzu1977的更多相关文章
- FZU1977 Pandora adventure —— 插头DP
题目链接:https://vjudge.net/problem/FZU-1977 Problem 1977 Pandora adventure Accept: 597 Submit: 2199 ...
- [FZU1977] Pandora adventure
来学插头DP了= = GDKOI前觉得不会考数位DP,GDOI前觉得插头DP用不上.. 结果令人伤感>_< 这题并不用增加状态.. 只要在形成环的时候,让形成环的位置在最后一个必走点之后, ...
- 初探插头dp
开学那个月学了点新东西,不知道还记不记得了,mark一下 感觉cdq的论文讲的很详细 题主要跟着kuangbin巨做了几道基础的 http://www.cnblogs.com/kuangbin/arc ...
随机推荐
- C# ---- GC中代的递增规律
只有当对象所在代被 Collect 了,改对象所在代才会加 1 ,代值最大为 2 示例1: using System; namespace myMethod { class People{} clas ...
- spring cloud: zuul(五): prefix访问前缀, ignoredServices粗粒度访问, yml不起作用
路由的前缀 - 问题 zuul.prefix: 我们可以指定一个全局的前缀 strip-prefix: 是否将这个代理前缀去掉 zuul: prefix: /ecom 我的eureka:http:// ...
- 细胞迁移 | cell migration
一些基本概念: intracellular biochemical signaling pathways:胞内生化信号通路 extracellular mechanical cues: 胞外机械信号 ...
- Mac必备神器之Go2Shell
一.作用 可以快速在当前目录打开Shell命令行窗口 二.安装 1.打开官网 http://zipzapmac.com/go2shell 2.点击下载并安装 3.点击应用图标 三. ...
- css对于文字过长加省略号
overflow: hiddentext-overflow: ellipsiswhite-space: nowrap
- jvm看java.lang.OutOfMemoryError: PermGen space
异常现象 异常信息如下 java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native M ...
- python记录_day18 反射 判断函数与方法
一.三个内置函数 1.issubclass(a, b) 判断a类是否是b类的子类 class Foo: pass class Zi(Foo): pass class Sun(Zi): pass pr ...
- Windows下dump文件生成与分析
一. 生成Dump文件方式 1.1任务管理器 在程序崩溃后,先不关闭程序,在任务管理器中找到该程序对应的进程.右键—>创建转储文件. 此时会在默认的目录下创建出一个dump文件. 可以看出 ...
- InnoDB存储引擎介绍-(4)Checkpoint机制一
检查点的工作机制: innodb会自动维护一个检查点的机制,叫做 fuzzy checkpointing(当然sharp checkpoint也是检查点之一),fuzzy checkpointing就 ...
- Sona
Sona Sona , Maven of the Strings . Of cause, she can play the zither. Sona can't speak but she can m ...