您当前的位置: 首页 > 

minato_yukina

暂无认证

  • 4浏览

    0关注

    135博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

P2922 [USACO08DEC]Secret Message G

minato_yukina 发布时间:2022-09-08 12:06:05 ,浏览量:4

在这里插入图片描述 题意:给定两个字符串(01)集合 S , T S,T S,T. 对于 T T T中的每个字符串 T i T_i Ti​,问 S S S中有多少个字符串和它匹配 思路:考虑下限制条件, ∑ b i + c i \sum b_i+c_i ∑bi​+ci​比较小. 对S建字典树,对于每个 T i T_i Ti​暴力匹配. 在匹配的时候 , 公共前缀会造成重复统计 , 如果直接统计匹配路径上的 c n t 在匹配的时候,公共前缀会造成重复统计,如果直接统计匹配路径上的cnt 在匹配的时候,公共前缀会造成重复统计,如果直接统计匹配路径上的cnt 比如说 S = 010 , T = 010111 比如说S=010,T=010111 比如说S=010,T=010111,这样路径上的 010 会被算作三次 , 但事实上只算 1 次 , 010会被算作三次,但事实上只算1次, 010会被算作三次,但事实上只算1次, 所以还需要一个数组 e n d [ p ] end[p] end[p]表示在 p p p这个位置终结的字符串有多少个. 我们只统计两个部分的字符串 1. e n d [ p ] end[p] end[p]统计这个,必然避免了一个前缀统计多次的情况,而且也不会漏掉 2.对于S中前缀长度很长的,也就是反过来T变成了S的前缀的情况 那么这部分的数目是 c n t [ p ] − e n d [ p ] cnt[p]-end[p] cnt[p]−end[p],在此时我们不能计算情况1的情况,因为它被纳入了 c n t [ p ] cnt[p] cnt[p]中

/*
I don't wanna be left behind,Distance was a friend of mine.
Catching breath in a web of lies,I've spent most of my life.
Catching my breath letting it go turning my cheek for the sake of this show
Now that you know this is my life I won't be told what's supposed to be right
Catch my breath no one can hold me back I ain't got time for that.
*/
#include
using namespace std;
const int maxn = 1e6+5;
const int INF = 1e9+7;
typedef long long ll;
typedef pair pii;
#define all(a) (a).begin(), (a).end()
#define pb(a) push_back(a)
vector G[maxn];
int tr[maxn][2];int cnt[maxn],idx = 0;
int ed[maxn];
void insert(vector &s){
	int p = 0, n=s.size();
	for(int i=0;iM>>N;
	for(int i=0;i>sz;vector tp(sz);
		for(int j=0;j>tp[j];
		}
		insert(tp);
	}
	for(int i=0;i>sz;vector tp(sz);
		for(int j=0;j>tp[j];
		cout            
关注
打赏
1663259277
查看更多评论
0.0473s