DAY 3

本篇博客记录了作者在算法竞赛中解决的三道难题,包括字符串压缩、递推序列计算和DNA字符串排列问题。通过动态规划、矩阵快速幂和组合数学方法分别求解,所有题目已AC。
摘要由CSDN通过智能技术生成

今日得分:20+100+39(终于在考场上A题了)

T1

题目大意:给你一个长度为n的01字符串,定义(A*k)(k>=2)为S=A+A+…+A(k个A)的合法压缩,可压缩一个合法压缩串,两个合法压缩串连在一起也是一个合法压缩串。求给定01字符串的子集(与原串的与等于自身的串)的合法压缩方案之和对998244353取模的结果。n<=100。

题解:每次枚举最后一段压缩的串,记忆化搜索强制全压缩的串和不强制全压缩的串,dp即可。状态数可以证明不是很多(上界是O(n^3+2^(n/8)),但这个上界非常非常的松)。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<ctime>
#include<map>
using namespace std;
inline int re_ad()
{
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+(ch^48),ch=getchar();
	return x*f;
}
const int mo=998244353;
string s;
map<string,int> mp[2];
int f(int now,string x)
{
	if(mp[now][x])return mp[now][x];
	register int i,j,k,n=x.length(),ret=0;//cout<<now<<" "<<n<<" "<<x<<endl;
	if(now)
	{
	for(i=0;i<n;++i)ret=(ret+1ll*f(1,x.substr(0,i))*f(0,x.substr(i,n))%mo)%mo;
	return mp[now][x]=ret;
	}
	else
	{
	for(i=1;i<n;++i)
	{
	if(n%i)continue;
	string t="";for(j=0;j<i;++j)t+='1';
	for(j=0;j<n;j+=i)
	for(k=0;k<i;++k)if(x[j+k]=
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值