hdu 6086 Rikka with String ac自动机+dp

2017多校第二场数据及标程 hdu 6045 Is Derek lying? 6046 hash 6047 Maximum Sequence 6048 Puzzle 6049 Sdjpx Is Happy 6050 Funny Function 6051 If the starlight never fade 6052 To my boyfriend 6053 TrickGCD 6054 String and String 6055 Regular polygon 立即下载


Rikka with String

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 210    Accepted Submission(s): 58


Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta has  n   01  strings  si , and he wants to know the number of  01  antisymmetric strings of length  2L  which contain all given strings  si  as continuous substrings.

A  01  string  s  is antisymmetric if and only if  s[i]≠s[|s|−i+1]  for all  i∈[1,|s|] .

It is too difficult for Rikka. Can you help her?

In the second sample, the strings which satisfy all the restrictions are  000111,001011,011001,100110 .
 

Input
The first line contains a number  t(1≤t≤5) , the number of the testcases. 

For each testcase, the first line contains two numbers  n,L(1≤n≤6,1≤L≤100) . 

Then  n  lines follow, each line contains a  01  string  si(1≤|si|≤20) .
 

Output
For each testcase, print a single line with a single number -- the answer modulo 998244353.
 

Sample Input
  
2 2 2 011 001 2 3 011 001
 

Sample Output
  
1 4
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6095  6094  6093  6092  6091 
 

Statistic |  Submit |  Discuss |  Note
题意:给你n个串,长度L,问你能构造出多少个字符串长度为2L满足包含这n个串以及他的反对称串。

思路:这题好恶心。。。调了大半天才调出来。很明显是ac自动机+dp。我们可以这么想,我们构造一个L的串,然后把他反对称就好了。那么前面包含的串它的反对称串也必定包含。所以构造ac自动机的时候把这n个串和他们的反对称串都插进去然后结尾标记为同一个状态。还有一个情况就是串出现的地方跨过了中间。例如样例中的011和001,若00出现在我们构造的串的最后,那么根据反对称中间会出现0011,也就是包含了011和001,所以我们把串拆开。把出现在结尾也可改变状态的串插入自动机。可能说明有点复杂,具体描述看官方博客的题解吧。下面给代码:

#include <bits/stdc++.h>

using namespace std;
#define maxn 5005
const int mod = 998244353;
struct Trie
{
	int next[maxn][2], fail[maxn], end1[maxn], end2[maxn], mark[maxn];
	int root, L;
	int newnode()
	{
		for (int i = 0; i<2; i++)
			next[L][i] = -1;
		end1[L] = 0;
		end2[L++] = 0;
		return L - 1;
	}
	void init()
	{
		memset(mark, -1, sizeof(mark));
		L  = 0;
		root = newnode();
	}
	void insert1(char buf[],int &id)
	{
		int len = strlen(buf);
		int now = root;
		for (int i = 0; i<len; i++)
		{
			if (next[now][buf[i] - '0'] == -1)
				next[now][buf[i] - '0'] = newnode();
			now = next[now][buf[i] - '0'];
		}
		if (mark[now]>=0){
			id=mark[now];
			return;
		}
		mark[now] = id;
		end1[now] |= 1 << mark[now];
	}
	void insert2(char buf[],int &id)
	{
		int len = strlen(buf);
		int now = root;
		for (int i = 0; i<len; i++)
		{
			if (next[now][buf[i] - '0'] == -1)
				next[now][buf[i] - '0'] = newnode();
			now = next[now][buf[i] - '0'];
		}
		end2[now] |= 1 << id;
	}
	void build()
	{
		queue<int>Q;
		fail[root] = root;
		for (int i = 0; i<2; i++)
		{
			if (next[root][i] == -1)
				next[root][i] = root;
			else
			{
				fail[next[root][i]] = root;
				Q.push(next[root][i]);
			}
		}
		while (!Q.empty())
		{
			int now = Q.front();
			Q.pop();
			end1[now] |= end1[fail[now]];
			end2[now] |= end2[fail[now]];
			for (int i = 0; i<2; i++)
			{
				if (next[now][i] == -1)
					next[now][i] = next[fail[now]][i];
				else
				{
					fail[next[now][i]] = next[fail[now]][i];
					Q.push(next[now][i]);
				}
			}
		}
	}
};
Trie ac;
const int maxlen=100;
void getsub(char *s,int id)
{
	int len=strlen(s);
	char ss[maxlen];
	strcpy(ss,s);
	ss[len]='\0';
	for(int i=1;i<len;i++)
	{
		int length=len-i+1;
		bool flag=true;
		bool leftover=false;
		bool rightover=false;
		for(int j=1;j<=length;j++)
		{
			if(i-j<0) 
			{
				leftover=true;
				break;
			}
			if(ss[i+j-1]==ss[i-j]) 
			{
				flag=false;
				break;
			}
		}
		if(flag)
		{
			char str[25];
			int now=0;
			if(leftover)
			{
				for(int j=len-1;j>=i;j--) str[now++]=!(ss[j]-'0')+'0';
			}
			else
			{
				for(int j=0;j<i;j++) str[now++]=(ss[j]-'0')+'0';
			}
			str[now]='\0';
			ac.insert2(str,id);
		}
		
	}
}
int dp[2][maxn][(1 << 6) + 5];
int main()
{
	int t;
	scanf("%d", &t);
	char buf[10][25];
	char s[25];
	while (t--){
		memset(dp, 0, sizeof(dp));
		int n, l;
		ac.init();
		int id=0;
		scanf("%d%d", &n, &l);
		for (int i = 0; i < n; i++){
			scanf("%s", buf[i]);
			int now=id;
			ac.insert1(buf[i],now);
			getsub(buf[i],now);
			strcpy(s,buf[i]);
			strrev(s);
			for(int j=0;s[j]!='\0';j++)
				s[j]=(!(s[j]-'0'))+'0';
			ac.insert1(s,now);
			if(now==id)
				id++;
		}
		ac.build();
		dp[0][0][0] = 1;
		int now=0;
		for (int i = 1; i <= l; i++){
			now^=1;
			memset(dp[now],0,sizeof(dp[now]));
			for (int j = 0; j < ac.L; j++)
				for (int k = 0; k < 1 << id; k++)
					for (int ll = 0; ll < 2; ll++){
						int Next = ac.next[j][ll];
						int nextstatus = k | ac.end1[Next];
						if (i == l)
							nextstatus |= ac.end2[Next];
						dp[now][Next][nextstatus] += dp[now^1][j][k];
						dp[now][Next][nextstatus] %= mod;
					}
		}
		int ans = 0;
		for (int i = 0; i < ac.L; i++){
			ans += dp[now][i][(1 << id) - 1];
			ans %= mod;
		}
		printf("%d\n", ans);
	}
}


【云原生技术】SonarQube 生态中PMD插件和P3C插件详细介绍 4. 在项目中如何选择 / 组合 1. 小团队、对《阿里规约》认同度高 → 直接启用 **P3C**,配合 SonarJava 基本够用。 2. 追求全面 Bug/安全检测 + 额外编码规范 → **SonarJava + PMD**(必要时加 P3C 少量规则)。 3. 大型多团队,希望“一本规约”统一风格 → **P3C 为主**,再补充 SonarJava/PMD 的 Bug 与安全规则。 4. 通过 Quality Gate 控制:将 **Blocker/Critical** Bug 阅读详情

相关推荐

IPD(集成产品开发)管理之道

IPD,是集成产品开发(Integrated Product Development)的缩写,它是集成了众多管理模型和理论、众多企业最佳管理实践的一整套体系,可以帮助企业快速响应市场变化、缩短产品上市时间、减少资源浪费、提高生产力,最终取得商业成功。IPD的思想最早来源于美国PRTM公司出版的《产品及生命周期优化法》一书中,该书详细描述了IPD模式所包含的各个方面。但IPD在中国的普及,源于IBM和华为的推行使用。IPD作为一套先进的产品研发管理模式,其成功的基础是功能部门和各团队之间的密切配合。

钢镚·真的博客 2713

HDU 6091 - Rikka with Match

思路 树形dp,设计状态如下: 设 $dp_u_i_0$表示 以点 u 为根的子树 最大匹配数模 m 为 i 时,且 u 点没有匹配的方案数 DP[u][i][1] 表示 以点 u 为根的子树 最大匹配数模 m 为 i 时,且 u 点匹配上的方案数 递推公式如下: DP[u][k][0](不匹配该节点) +=   ∑ [i+j==k] ...

weixin_30765319的博客 195

creo二次开发使用映射

在creo进行二次开发时,一些无法直接通过访问底层代码来对特征进行操作,比如“镜像装配”,这个时候就可以使用映射(Mapkey)来完成一键镜像。 注:这是镜像装配的代码 ProError status; ProMacro macro; wstring Macro; strMacro = L"mapkey(continued) ~ Command ProCmdMirrorAssem ; mapkey(continued) ~ Activate mirror_component_dialog Sy

qq_49328512的博客 1608

bestcoder Rikka with string

Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: One day, Yuta got a ...

bandiaodai5734的博客 192

YOLOv5实战:无人机巡检图片差异对比与违建标记(附完整代码)

本文详细介绍了如何利用YOLOv5目标检测技术实现无人机巡检图片差异对比与违建标记。通过图像对齐、目标检测、差异分析和可视化标记四个步骤,构建高效的违建识别系统,显著提升城市管理效率。文章包含完整代码实现和性能优化技巧,为计算机视觉在无人机巡检中的应用提供实用指南。

weixin_42535720的博客 281

小麦病害检测系统开发

本项目旨在针对小麦病害小目标检测任务,在YOLOv11基础上进行三项改进: - 将主干网络替换为Swin Transformer,增强全局特征提取能力。 - 在检测头中引入DynamicHead,并增加检测头数量至四个,提升多尺度检测性能。 - 集成半监督FixMatch训练框架,利用无标签数据提升模型泛化能力。 我们定义五个模型进行对比实验: - Model 0: 原始YOLOv11 (有监督) - Model 1: YOLOv11 + Swin Transformer (有监督) ~~~~~~

AI的内部世界的博客 121

【hdu6091】Rikka with Match(【xsy2543】恐怖分子)【线段树】

题意 n*m方格上有K个障碍点,Q次询问以一个点为顶点的矩形中不内含障碍点的有多少个 题解 以蓝圈为询问点的另一矩形顶点在下图范围(红圈为障碍点) 于是把图分成(左上,右下,左下,右上)四块,对于每一块计算贡献 可以把当前计算的边角位放在左下,按x扫描线,用线段树维护答案 这里的线段树类似李超线段树,比较复杂,我不会用文字表述qwq,请看代码+画图理解 时间O(n∗log2(n))O(n*log...

ezoixx118的博客 316

软件崩溃时Visual Studio中看不到有效的调用堆栈,使用Windbg动态调试去分析定位

当在Visual Studio中遇到软件崩溃且无法查看详细调用堆栈时,可以使用Windbg进行动态调试去分析定位问题。

dvlinker的技术专栏 1万+

hdu 6091 Rikka with Match

题   OvOhttp://acm.hdu.edu.cn/showproblem.php?pid=6091   (2017 Multi-University Training Contest - Team 6- 1007) 解   记 f[i][j]表示,以i为根的子树的所有子图(包含子树所有节点,删掉一些边得到的子图)中,符合下列条件的子图的个数     1. 记子图最大匹配为h...

weixin_30410999的博客 178

App 抓包难?Frida Hook 实战:绕过 SSL Pinning (证书绑定) 抓取某大厂 App 核心接口

当我们使用 Charles 抓包 HTTPS 时,本质上是实施了MITM(中间人攻击)。Charles 伪装成服务器,发给 App 一个自己的证书(伪造证书)。Charles 伪装成 App,拿着真正的证书去请求服务器。如果 App 只是简单校验“证书是否由受信任的 CA 签发”,那你把 Charles 的根证书安装到手机系统里,就能骗过它。但是,是 App 内置了服务器证书的Hash(指纹)。

BUG猿的博客 916

Vibe Writing 手把手教程:Obsidian + Claudian + Skill

本文介绍了Vibe Writing的实操教程,主要使用Obsidian+Claudian+Skill组合。教程包含工具安装配置(Obsidian、Claudian插件)、核心工作流(选题-调研-写作-发布)和效果对比。重点展示了Claude Code生成的文本更具"人味"和场景感,优于其他AI工具。作者强调工具只是辅助,内容灵魂仍需个人思考积累。附有公众号排版和全网发布工具推荐,以及自动配图生成方案。

299

Hdu-6086 Rikka with String(AC自动机+DP)

As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has n 01 strings si, and he wants to

WZJRJ28 436

华为ONU远程登录管理配置

华为P602E、EG8040CONU、EG8240H5、W626E等ONU、ONT默认无法配置管理IP,无法远程telnet登录管理。校园网项目中因故障诊断需要远程登录ONU可以通过OLT的远程WEB代理功能链接登录,具体配置如下:

symstandsun的博客 6109

HDU - 6086 Rikka with String AC自动机 + dp

HDU - 6086 前缀和后缀分别建AC自动机, 考虑从两端往中间dp dp[ o ][ i ][ j ][ mask ] 表示放了前面和后面o个, 第一个自动机在 i 位置, 第二个自动机在 j 位置, 拥有的目标串的状态是mask的方案数。 对于跨过两端的东西, 我们最后处理就好了。 #include<bits/stdc++.h> #define LL long l...

weixin_30386713的博客 104

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

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

HDU 6086 Rikka with String ——(AC自动机 + DP)

  这是一个AC自动机+dp的问题,在中间的串的处理可以枚举中断点来插入自动机内来实现,具体参见代码。   在这题上不止为何一直MLE,一直找不到结果(lyf相同写法的代码消耗内存较少),还好考虑到这题节点应该不会过多,可以少开一点节点数。   代码如下: 1 #include <bits/stdc++.h> 2 using namespace std; ...

ddmxynl793173的博客 260

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Rikka with String HDU - 6086 多校#5 AC自动机DP

有之前的铺垫这题感觉好做多了。。 跟之前不同的就在于对称轴节点要特殊标记 #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define ull unsigned

Dream in the Night 376

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

hdu 6086 Rikka with String(AC自动机+状压dp)

题目链接:hdu 6086 Rikka with String 题意: 给你n个只含01的串,和一个长度L,现在让你构造出满足s[i]≠s[|s|−i+1] for all i∈[1,|s|],长度为2L,并且包含给出的n个串,问能有多少种这样的串。 题解: 建立两个AC自动机,一个用来放正串,一个用来放反串。 由于题目有限制条件,所以前L长度的字符一确定,后L长度的字符就确定了。 ...

weixin_30445169的博客 141

【HDU6086】Rikka with String-AC自动机+状压DP

测试地址:Rikka with String 题目大意:给定nnn个010101串,问有多少长为2m2m2m的反对称010101串包含这nnn个串作为子串。一个串反对称当且仅当对于每个字符si(1≤i≤|s|)si(1≤i≤|s|)s_i(1\le i\le |s|)都有si≠s|s|−i+1si≠s|s|−i+1s_i\ne s_{|s|-i+1}。 做法:本题需要用到AC自动机+状压DP。...

Maxwei_wzj的OI世界 372

HDU 6086 Rikka with String AC自动机 + DP

Rikka with String Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:Yuta hasn01s...

weixin_30271335的博客 165

【AC自动机】【状压dp】【滚动数组】hdu6086 Rikka with String

给你m个01串,问你有多少个长度为2L的01串,满足前半段倒置取反后等于后半段,并且包含所有的m个01串。 考虑单词完全在中线前面或者后面的情况,直接将单词及其倒置取反插入AC自动机,AC自动机每个结点用个tag压位记录单词集合。 对于跨越中线的情况,比如说110010是一个单词,枚举一个中线, 11|0010 在前面添加上10,变成1011|0010, 那么其前半部分1011...

weixin_33805557的博客 113

hdu 6086 -- Rikka with String(AC自动机 + 状压DP)

题目链接   Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has n 01 strings si

nginxs的博客 303

HDU 6086 Rikka with String (AC 自动机+状压 dp, 2017 Multi-Univ Training Contest 5)

ProblemAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:Yuta has n 01 strings si, and he wants to know the n

DorMOUSENone的博客 1107
上一篇: 边双连通分量模板
下一篇: hdu 6097 Mindis (反演点)
overload1997
博客等级 码龄11年 328粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值