[BZOJ]1814 Ural 1519 Formula 1 插头DP

深入解析安卓性能分析工具systrace/atrace的使用技巧与实战场景 本文深入解析了安卓性能分析工具systrace/atrace的核心使用技巧与实战场景。文章澄清了环境搭建的常见误区,详细拆解了命令参数,并通过列表卡顿、启动优化等具体案例,手把手指导开发者利用这些工具精准定位性能瓶颈,提升应用流畅度。 阅读详情

1814: Ural 1519 Formula 1

Time Limit: 1 Sec   Memory Limit: 64 MB
Submit: 879   Solved: 328
[ Submit][ Status][ Discuss]

Description

Regardless of the fact, that Vologda could not get rights to hold the Winter Olympic games of 20**, it is well-known, that the city will conduct one of the Formula 1 events. Surely, for such an important thing a new race circuit should be built as well as hotels, restaurants, international airport - everything for Formula 1 fans, who will flood the city soon. But when all the hotels and a half of the restaurants were built, it appeared, that at the site for the future circuit a lot of gophers lived in their holes. Since we like animals very much, ecologists will never allow to build the race circuit over the holes. So now the mayor is sitting sadly in his office and looking at the map of the circuit with all the holes plotted on it. Problem Who will be smart enough to draw a plan of the circuit and keep the city from inevitable disgrace? Of course, only true professionals - battle-hardened programmers from the first team of local technical university!.. But our heroes were not looking for easy life and set much more difficult problem: "Certainly, our mayor will be glad, if we find how many ways of building the circuit are there!" - they said. It should be said, that the circuit in Vologda is going to be rather simple. It will be a rectangle N*M cells in size with a single circuit segment built through each cell. Each segment should be parallel to one of rectangle's sides, so only right-angled bends may be on the circuit. At the picture below two samples are given for N = M = 4 (gray squares mean gopher holes, and the bold black line means the race circuit). There are no other ways to build the circuit here. 一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数

Input

The first line contains the integer numbers N and M (2 ≤ N, M ≤ 12). Each of the next N lines contains M characters, which are the corresponding cells of the rectangle. Character "." (full stop) means a cell, where a segment of the race circuit should be built, and character "*" (asterisk) - a cell, where a gopher hole is located.

Output

You should output the desired number of ways. It is guaranteed, that it does not exceed 2^63-1.

Sample Input

4 4
**..
....
....
....



Sample Output


2

HINT

Source

[ Submit][ Status][ Discuss]


HOME Back

  插头DP比起其他DP还真的是骨(dai)骼(ma)精(ju)奇(chang)啊... 不过能想到插头这样一个很好的比喻还是非常6. cdq的讲稿非常清晰, 可惜万恶的百度文库需要1下载券... 搞得我花掉了我(b)自(f)己(k)的一个下载券... 这里附上一个同样清晰明了的讲解: 插头DP——从不会到崩溃. 说着崩溃讲的还是很好的嘛~ 但是确实恶心. 省选考到我就gg(flag). 这道题就是裸题啦~

#include<bits/stdc++.h>
#define clear(a) memset(a, 0, sizeof(a))
using namespace std;
typedef long long lnt;
const int maxn = 2e5 + 5;
char s[15];
lnt ans, dp[2][maxn];
int n, m, c, cnt, ex, ey, tot[2], bit[20];
int mp[15][15], h[maxn], sta[2][maxn];
struct edge{int nxt, v;}e[maxn];
inline void insert(const int &s, const lnt &num) {
	int u = s % maxn;
	for (int i = h[u]; i; i = e[i].nxt)
		if (sta[c][e[i].v] == s) {
			dp[c][e[i].v] += num;
			return;
		}
	e[++ cnt].v = ++ tot[c];
	e[cnt].nxt = h[u], h[u] = cnt;
	sta[c][tot[c]] = s, dp[c][tot[c]] = num;
}
inline void Plug_Dp() {
	tot[0] = 1, dp[c][1] = 1;
	register int i, j, k, t;
	for (i = 1; i <= n; ++ i) {
		for (j = 1; j <= tot[c]; ++ j)
			sta[c][j] <<= 2;
		for (j = 1; j <= m; ++ j) {
			clear(h), cnt = 0;
			c ^= 1, tot[c] = 0;
			for (k = 1; k <= tot[c ^ 1]; ++ k) {
				int s = sta[c ^ 1][k];
				lnt num = dp[c ^ 1][k];
				int p = (s >> bit[j - 1]) & 3;
				int q = (s >> bit[j]) & 3;
				if (!mp[i][j]) {
					if (!p && !q) insert(s, num);
				}
				else if (!p && !q) {
					if (!mp[i + 1][j] || !mp[i][j + 1]) continue;
					s += (1 << bit[j - 1]) + (1 << (bit[j] + 1));
					//左括号是0, 右括号是1, 四进制在二进制下两位表示一字节 
					insert(s, num);
				}
				else if (!p && q) {
					if (mp[i][j + 1]) insert(s, num);
					if (mp[i + 1][j]) {
						s += (1 << bit[j - 1]) * q - (1 << bit[j]) * q;
						insert(s, num);
					}
				}
				else if (p && !q) {
					if (mp[i + 1][j]) insert(s, num);
					if (mp[i][j + 1]) {
						s += (1 << bit[j]) * p - (1 << bit[j - 1]) * p;
						insert(s, num);
					}
				}
				else if (p + q == 2) {
					int b = 1;
					for (t = j + 1; t <= m; ++ t) {
						int v = (s >> bit[t]) & 3;
						if (v == 1) b ++; //根据括号序列的性质
						if (v == 2) b --;
						if (!b) {
							s -= (1 << bit[t]);
							break;
						}
					}
					s -= (1 << bit[j - 1]) + (1 << bit[j]);
					insert(s, num);
				}
				else if (p + q == 4) {
					int b = 1;
					for (t = j - 2; ~t; -- t) {
						int v = (s >> bit[t]) & 3;
						if (v == 2) b ++;
						if (v == 1) b --;
						if (!b) {
							s += (1 << bit[t]);
							break;
						}
					}
					s -= (1 << (bit[j - 1] + 1)) + (1 << (bit[j] + 1));
					insert(s, num);
				}
				else if (p == 2 && q == 1) {
					s -= (1 << (bit[j - 1] + 1)) + (1 << bit[j]);
					insert(s, num);
				}
				else if (p == 1 && q == 2) {
					if (i == ex && j == ey) ans += num;
				}
			}
		}
	}
	printf("%lld\n", ans);
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < 26; ++ i)
		bit[i] = i << 1;
	for (int i = 1; i <= n; ++ i) {
		scanf("%s", s + 1);
		for (int j = 1; j <= m; ++ j)
			if (s[j] == '.') mp[i][j] = 1, ex = i, ey = j;
	}
	Plug_Dp();
	return 0;
}


【2023】Java利用modbus4j实现工业设备Modbus TCP数据采集与解析 本文详细介绍了在2023年使用Java和modbus4j库实现工业设备Modbus TCP数据采集与解析的完整实践。内容涵盖开发环境搭建、TCP连接建立、开关量与模拟量数据的读取与解析、批量读取性能优化、控制指令写入以及常见错误排查指南,为开发者构建稳定高效的工业物联网数据采集系统提供全面指导。 阅读详情

相关推荐

Vast.ai GPU服务器租用与SSH密钥连接实战指南

本文详细介绍了如何在Vast.ai平台租用GPU服务器并通过SSH密钥安全连接的全流程。从注册、选配GPU型号到SSH密钥生成与配置,再到实战中的端口转发和文件传输技巧,帮助用户高效利用云端GPU资源进行深度学习等计算密集型任务。

weixin_29574585的博客 524

【BZOJ1814】Ural 1519 Formula 1 (插头dp)

【BZOJ1814】Ural 1519 Formula 1 (插头dp) 题面 BZOJ Vjudge 题解 戳这里 上面那个链接里面写的非常好啦。 然后说几个点吧。 首先是关于为什么只需要考虑三进制状态,因为哈密顿回路是不可能出现自交的,因此对于当前的轮廓线一定直接分割了哈密顿回路的一部分,不可能出现只考虑分割出来的情况下,存在插头的连通性直接交叉,否则一定不合法(比如说四个连续位置,你不可能\...

weixin_30421809的博客 166

Zemax显微镜设计:从物镜到目镜的完整光学系统优化

本文详细介绍了使用Zemax进行显微镜光学系统设计的完整流程,从物镜到目镜的优化技巧。通过实战案例和关键参数设置,帮助读者掌握数值孔径、视场角等核心概念,实现高分辨率显微镜设计。文章特别强调了系统级优化和公差分析的重要性,为科研和工业检测提供可靠的光学解决方案。

weixin_42549451的博客 435

【BZOJ1814】Ural 1519 Formula 1

【题目链接】点击打开链接【思路要点】基于连通性的的动态规划模板题。时间复杂度\(O(3^M*N*M)\)。【代码】#include&lt;bits/stdc++.h&gt; using namespace std; #define MAXN 30 #define TMPN 15 #define HASH 1000005 #define P 100003 struct Hash_Table { i...

cz_xuyixuan的博客 367

OpenClaw 企业级自动化系统架构设计与实现

本文介绍基于 OpenClaw 构建的企业级自动化系统的完整架构设计、技术选型、实现细节和性能优化方案。

2604_95445636的博客 482

AD9176 双通道高速DAC调试记录

AD9176是一款高性能双通道16位数模转换器,支持高达12.6GSPS采样率,专为多频段无线应用设计。该器件集成8通道15.4Gbps JESD204B接口,支持复数/实数数据输入,每通道最大输入速率达3.08GSPS。关键特性包括:48位高精度NCO、灵活的插值滤波器(最高12倍)、优异的动态性能(SFDR达-83dBc@1.84GHz)以及多芯片同步功能。硬件调试需重点关注时钟配置(建议250M基准时钟)、JESD参数匹配及交流耦合设计。测试指标要求SFDR>55dBc@312MHz,实测值可达65d

universaldata的博客 1489

bzoj 1814 Fornula 1

Formula 1 题意 在\(n*m\)的矩阵中,有些格子有树,没有树的格子不能到达,找一条回路,吃完所有的树,求有多少种方法。 解法 因为只要一条回路,所以我们必须维护插头的连通性。 具体的可以参照 这位大佬的博客 代码 注意开long long。 #include <cstdio> #include <cstdlib> #include <iostream&gt...

weixin_30709809的博客 171

IgH EtherCAT 从入门到精通:第 29 章 实战:EoE 远程维护通道搭建

摘要:本章详细介绍了基于EoE(Ethernet over EtherCAT)协议的远程维护通道搭建方案。主要内容包括:1)网络架构设计,采用管理网络与EoE子网隔离的方案;2)从站EoE支持确认与IP地址配置,提供API和命令行两种方式;3)路由/交换两种部署模式,重点推荐路由模式并给出自动化配置脚本;4)SSH远程访问配置,包括直接连接和跳板访问两种方式;5)安全加固措施,如防火墙规则、SSH密钥认证等;6)故障恢复机制与性能注意事项。该方案实现了通过EtherCAT网络对从站设备的远程SSH访问、文件

从事嵌入式linux android驱动开发,拥有全栈能力 360

URAL 1519 Formula 1(插头DP)

1519. Formula 1 Time limit: 1.0 second Memory limit: 64 MB Background Regardless of the fact, that Vologda could not get rights to hold the Winter Olympic games of 20**, it is well-known,

yasolx的博客 799

PCL 逐点插入法构建Delaunay三角网(C++详细过程版)

点云构建Delaunay三角网的逐点插入法基于PCL点云库的C++详细过程版实现

点云侠的博客 2991

文末含资料链接和视频讲解!YOLOv8+RepVGG+QueryDet小目标检测终极指南:从理论到实战,突破遥感图像检测难题

QueryDet(Query Detection)机制代表了目标检测领域的一个重要范式转变。传统的目标检测方法基于anchor或anchor-free的密集预测,需要为图像中的每个可能位置生成预测。而QueryDet采用了稀疏查询的方式,通过少量的可学习查询向量来直接预测目标。 这种设计灵感来源于Transformer架构中的注意力机制。在自然语言处理中,Transformer通过query-key-value机制实现了高效的序列建模。QueryDet将这一思想引入到目标检测中,将检测问题转化为查询匹配问

FJN110的博客 384

bzoj 1814: Ural 1519 Formula 1【插头dp】

设f[i][j][s]为轮廓线推到格子(i,j),状态为s的方案数 括号表示一段线的左端和右端,表示成左括号和右括号,状压的时候用1和2表示,0表示已经闭合 下面的蓝线是黄色格子的轮廓线,dp转移要把它转到橙色轮廓线,设已经在状压的s中取到两条边的状态记为b1,b2 然后分很多情况讨论: (i,j)是障碍:那就只能什么都不放的转移,也就是只能从b1=0,b2=0转移到新轮廓线的b1=0,b2=0...

weixin_30793643的博客 155

无法将“choco”项识别为 cmdlet、函数、脚本文件或可运行程序的名称的解决方案

本文主要介绍了无法将“choco”项识别为 cmdlet、函数、脚本文件或可运行程序的名称的解决方案,希望能对使用wIndows的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 12万+

【BZOJ1814】Ural 1519 Formula 1 插头DP

【BZOJ1814】Ural 1519 Formula 1 题意:一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数。(n,m<=12) 题解:插头DP板子题,刷板子,附带题解链接。 如何存放状态呢?可以采用hash,我们的hash表形如一个队列,每次新加入一个状态时,就沿着这个状态在队列中对应的hash值不断向后找,直到找到这个状态或者发现一个...

aodanchui1057的博客 213

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

bzoj 1814 Ural 1519 Formula 1 ——插头DP

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1814 普通的插头 DP 。但是调了很久。注意如果合并两个 1 的话,不是 “把向右第一个 2 该成 1 ”,而是 “把向右第一个没有与 1 匹配的 2 改成 1 ”。 原来获取哈希值是用字符串哈希的方法,遍历12个位置;太慢。直接对某数取模作为哈希值,手写哈希表保证不会找错状态。大概 1...

weixin_30734435的博客 75

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

bzoj1814 Ural 1519 Formula 1(插头DP)

对插头DP的理解还不是很透彻。 先说一下肤浅的理解吧。 插头DP使用范围:指数级复杂度,且适用于解决网格图连通性问题,如哈密顿回路等问题。插头一般指每相邻2个网格的接口。 题目难度:一般不可做。 使用三进制状态,用0表示没有插头,1表示左括号插头,2表示右括号插头,而由于位运算常数特别小,可以采用四进制+手工hash的做法。处理好状态与编号的对应关系后进行dp,复杂度就只与合法状...

weixin_30730053的博客 138

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

插头DP讲解+[BZOJ1814]:Ural 1519 Formula 1(插头DP)

1.什么是插头$DP$? 插头$DP$是$CDQ$大佬在$2008$年的论文中提出的,是基于状压$D$P的一种更高级的$DP$多用于处理联通问题(路径问题,简单回路问题,多回路问题,广义回路问题,生成树问题)。 插头$DP$每道题都不一样,且需要进行较为繁琐的分类讨论,所以插头$DP$十分锻炼思维的严谨性和全面性。 2.插头$DP$思路  $\mathcal{A.}$状态确立...

weixin_30394251的博客 362

bzoj1814: Ural 1519 Formula 1 插头dp

bzoj1814: Ural 1519 Formula 1 Description Regardless of the fact, that Vologda could not get rights to hold the Winter Olympic games of 20**, it is well-known, that the city will conduct one of th...

maxtir的博客 380

bzoj1814 Ural 1519 Formula 1 插头dp

Description 一个 n * m 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数 2 ≤ N, M ≤ 12 Solution 插头dp入门题。。 我们设f[i,j,S]表示递推到第i行第j列,轮廓线上插头连通性状态为S的方案数。所谓轮廓线就是已经dp过格子下边界加上当前格子的右边界组成的一条折线。所谓插头就是路径在轮廓线上的走向。 我们用三进制表示轮廓线状态,0表示无...

olahiuj的博客 355

【bzoj1814】Ural 1519 Formula 1 插头dp

题目描述 一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数。 输入 The first line contains the integer numbers N and M (2 ≤ N, M ≤ 12). Each of the next N lines contains M characters, which are the correspondi...

weixin_30252155的博客 154

bzoj 1814 Ural 1519 Formula 1 插头DP

1814: Ural 1519 Formula 1 Time Limit: 1 SecMemory Limit: 64 MBSubmit: 942Solved: 356[Submit][Status][Discuss] Description Regardless of the fact, that Vologda could not get rights to hold t...

weixin_30755709的博客 139

bzoj1814 Ural 1519 Formula 1(插头dp模板题)

1814: Ural 1519 Formula 1 Time Limit:1 SecMemory Limit:64 MBSubmit:924Solved:351[Submit][Status][Discuss] Description 一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数 Input The first line...

weixin_30889885的博客 123

BZOJ1814: Ural 1519 Formula 1(插头Dp)

Description Regardless of the fact, that Vologda could not get rights to hold the Winter Olympic games of 20**, it is well-known, that the city will conduct one of the Formula 1 events. Surely, for s...

weixin_30338481的博客 203

bzoj 1814: Ural 1519 Formula 1 插头dp经典题

  用的括号序列,听说比较快。   然并不会预处理,只会每回暴力找匹配的括号。    1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define N 199917 6 #define ...

weixin_30853329的博客 107

BZOJ 1814 Ural 1519 Formula 1

题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1814 题解 插头dp,枚举边界线的插头,分类讨论转移点上插头和左插头的情况,来转移这个点的插头。 代码 #include <cstdio> #include <cstring> #in...

dilei7762的博客 166
上一篇: [BZOJ]2734 [HNOI2012] 集合选数 状压DP 思路神题
下一篇: [BZOJ]2064 分裂 状压DP 思路神题
MaxMercer
博客等级 码龄10年 55粉丝 261原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值