http://acm.timus.ru/problem.aspx?space=1&num=1519

https://vjudge.net/problem/URAL-1519

题目大意:给一个网格,有些网格有障碍,问有多少条哈密顿回路。

——————————————————-

插头dp模板题,详见:http://www.cnblogs.com/luyouqi233/p/8256778.html

参考代码和思路于:http://www.yhzq-blog.cc/%E6%8F%92%E5%A4%B4dp-%E4%BB%8E%E4%B8%8D%E4%BC%9A%E5%88%B0%E5%B4%A9%E6%BA%83/

#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int INF=;
const int mod=;
const int M=;
struct node{
int to,nxt;
}edge[M];
int head[M],cnt;
int n,m,e1,e2;
bool mp[][]; //记录是否有障碍
int cur,pre; //滚动数组
int state[][M]; //记录状态,滚动
ll ans[][M],cntt; //记录答案
int tot[]; //记录状态总数
int bit[]; //提取状态使用
inline void getbit(){
for(int i=;i<;i++)bit[i]=i<<;
return;
}
inline void add(int u,int v){
cnt++;
edge[cnt].to=v;
edge[cnt].nxt=head[u];
head[u]=cnt;
return;
}
void insert(int now,ll num){
int u=now%mod;
for(int i=head[u];i;i=edge[i].nxt){
int v=edge[i].to;
if(state[cur][v]==now){
ans[cur][v]+=num;
return;
}
}
add(u,++tot[cur]);
state[cur][tot[cur]]=now;
ans[cur][tot[cur]]=num;
return;
}
void plugdp(){
cur=;
tot[cur]=;
ans[cur][]=;
state[cur][]=;
for(int i=;i<=n;i++){
for(int j=;j<=tot[cur];j++){
state[cur][j]<<=;
}
for(int j=;j<=m;j++){
memset(head,,sizeof(head));cnt=;
pre=cur,cur^=;
tot[cur]=;
for(int k=;k<=tot[pre];k++){
int now=state[pre][k];
ll num=ans[pre][k];
int is_down=(now>>bit[j-])%;
int is_right=(now>>bit[j])%;
if(!mp[i][j]){
if(!is_down&&!is_right)
insert(now,num);
}
else if(!is_down&&!is_right){
if(mp[i][j+]&&mp[i+][j])
insert(now+(<<bit[j-])+*(<<bit[j]),num);
}
else if(!is_down&&is_right){
if(mp[i][j+])
insert(now,num);
if(mp[i+][j])
insert(now-is_right*(<<bit[j])+is_right*(<<bit[j-]),num);
}
else if(is_down&&!is_right){
if(mp[i+][j])
insert(now,num);
if(mp[i][j+])
insert(now-is_down*(<<bit[j-])+is_down*(<<bit[j]),num);
}
else if(is_down==&&is_right==){
int count=;
for(int l=j+;l<=m;l++){
if((now>>bit[l])%==)count++;
if((now>>bit[l])%==)count--;
if(!count){
insert(now-(<<bit[l])-(<<bit[j-])-(<<bit[j]),num);
break;
}
}
}
else if(is_down==&&is_right==){
int count=;
for (int l=j-;l>=;l--){
if((now>>bit[l])%==) count--;
if((now>>bit[l])%==) count++;
if(!count){
insert(now+(<<bit[l])-*(<<bit[j-])-*(<<bit[j]),num);
break;
}
}
}
else if(is_down==&&is_right==)
insert(now-*(<<bit[j-])-(<<bit[j]),num);
else if(is_down==&&is_right==){
if(i==e1&&j==e2)
cntt+=num;
}
}
}
}
return;
}
int main(){
getbit();
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
char ch=getchar();
while(ch!='*'&&ch!='.')ch=getchar();
if(ch=='.')mp[i][j]=,e1=i,e2=j;
}
}
plugdp();
printf("%lld\n",cntt);
return ;
}

URAL1519:Formula 1——题解的更多相关文章

  1. URAL1519 Formula 1 —— 插头DP

    题目链接:https://vjudge.net/problem/URAL-1519 1519. Formula 1 Time limit: 1.0 secondMemory limit: 64 MB ...

  2. URAL1519 Formula 1 【插头dp】

    题目链接 URAL1519 题解 看题型显然插头\(dp\) 考虑如何设计状态 有这样一个方案 当我们决策到某个位置 轮廓线长这样 你会发现插头一定是相互匹配的 所以我们实际上可以把状态用括号序列表示 ...

  3. 2019.01.23 ural1519 Formula 1(轮廓线dp)

    传送门 轮廓线dpdpdp模板题. 题意简述:给一个放有障碍的网格图,问有多少种方法能使所有非障碍格子都在同一条哈密顿回路上面. 考虑用括号序列的写法来状压这个轮廓线. 用000表示没有插头,111表 ...

  4. [URAL1519] Formula 1 [插头dp入门]

    题面: 传送门 思路: 插头dp基础教程 先理解一下题意:实际上就是要你求这个棋盘中的哈密顿回路个数,障碍不能走 看到这个数据范围,还有回路处理,就想到使用插头dp来做了 观察一下发现,这道题因为都是 ...

  5. DP设状态 : 状压与线

    [NOIP2017]宝藏(状压) [AHOI2009]中国象棋(状压) [BZOJ1814] URAL1519 Formula 1(插头\(DP\)模板) 新链接 : Luogu5056 , dark ...

  6. HDU1964 Pipes —— 插头DP

    题目链接:https://vjudge.net/problem/HDU-1964 Pipes Time Limit: 5000/1000 MS (Java/Others)    Memory Limi ...

  7. FZU1977 Pandora adventure —— 插头DP

    题目链接:https://vjudge.net/problem/FZU-1977  Problem 1977 Pandora adventure Accept: 597    Submit: 2199 ...

  8. Gym 101480F Frightful Formula(待定系数)题解

    #include<cmath> #include<set> #include<map> #include<queue> #include<cstd ...

  9. Codeforces Gym 100610 Problem E. Explicit Formula 水题

    Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

随机推荐

  1. 前端--再遇jQuery

    一.属性 属性(如果你的选择器选出了多个对象,那么默认只会返回第一个属性) attr(属性名|属性值) --一个参数是获取属性的值,两个参数是设置属性值 --点击图片加载示例 removeAttr(属 ...

  2. ubuntu apt-xxx

    1. apt-get install xxx 2. dpkg -l ; list software already installed. 3. apt-cache dumpavail ; print ...

  3. 使用SKlearn(Sci-Kit Learn)进行SVR模型学习

    今天了解到sklearn这个库,简直太酷炫,一行代码完成机器学习. 贴一个自动生成数据,SVR进行数据拟合的代码,附带网格搜索(GridSearch, 帮助你选择合适的参数)以及模型保存.读取以及结果 ...

  4. 用vsstudio 设计Winform 高分屏上布局错乱的问题

    在使用win10高分辨率150%,200%系统进行winform开发时, 会有布局错乱的现象,比如之前定义的300px的宽度,往往被设置成600px (200%分辨率下). 这个问题vs2015的解决 ...

  5. 【转】React-Native 实现增量热更新的思路

    所谓热更新就是在不重新安装的前提下进行代码和资源的更新,相信在整个宇宙中还不存在觉得热更新不重要的程序猿. 增量热更新就更牛逼了,只需要把修改过和新增的代码和资源推送给用户下载即可,增量部分的代码和资 ...

  6. 20181023-10 Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 07

    作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2290 Scrum master:范靖旋 一.小组介绍 组长:王一可 组员: ...

  7. 软件工程团队项目第一个Sprint评论

    (1)跑男:话说我没怎么听懂这个游戏是怎么玩的,可能是由于这是第一组,所以我没有反应过来把,界面设计的还可以,但是像设置,选关,帮助真心没看懂.有一种感觉就是,这个游戏是由一堆的漂亮的图片拼起来的,还 ...

  8. c# Webservice技术整理

    因为平常项目中使用webservice比较少,然后就将本来不太熟悉的webservice给忘记掉了.所以再次整理如下: 百度搜索关键词 :c# webservice 1. 联接地址: http://w ...

  9. 2nd 四人小组项目的进一步分析

    组长:林莉 组员:王东涵.宫丽君.胡丽娜 项目选题:车辆管理系统(附加相关员工管理) 项目期限:暂定十周 一.NABCD模型 N-Need 需求分析及相应功能设置 需求概述: 管理库中车辆信息.相关人 ...

  10. PAT 甲级 1027 Colors in Mars

    https://pintia.cn/problem-sets/994805342720868352/problems/994805470349344768 People in Mars represe ...