Codeforces 271D Good Substrings 暴力+Trie
来源:互联网 发布:sql语句高级教程 编辑:程序博客网 时间:2024/05/16 12:18
点击打开链接
枚举substring 开头 直到右端点R非法 map标记重复,O(n^2logn) TLE了
在标记重复上进行优化,用Trie保存所有的substring,枚举开头,遍历Trie,若该结点没访问过,标记后ans++即可 O(n^2)
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e3+20;string s,a;int b[N],k;int ch[N*N][30],val[N*N];//trieint root,num;void insert(int l,int r){int u=0;for(int i=l;i<r;i++){int id=s[i]-'a';if(!ch[u][id])ch[u][id]=++num;u=ch[u][id];val[u]=1;}val[u]=1;//}int query(int l,int r){int res=0,cnt=0;int u=0;for(int i=l;i<r;i++){int id=s[i]-'a';u=ch[u][id];if(a[id]=='0')cnt++;if(cnt<=k)res+=val[u],val[u]=0;//val[u]清零 elsereturn res;}return res;}int main(){ while(cin>>s>>a>>k) { int ans=0; memset(ch,0,sizeof(ch));num=0; int len=s.length(); for(int i=0;s[i];i++)//把所有的substring插入到Trie insert(i,len); for(int i=0;s[i];i++)//O(n^2)ans+=query(i,len);cout<<ans<<endl;}return 0;}
0 0
- Codeforces 271D Good Substrings 暴力+Trie
- CF 271D Good Substrings(trie树)
- Codeforces 451D Count Good Substrings
- codeforces 451D Count Good Substrings 枚举
- Codeforces 451D Count Good Substrings
- 【杂题】 codeforces 451D Count Good Substrings
- Codeforces 451 D. Count Good Substrings
- CodeForces 451D Count Good Substrings
- codeforces 451 D.Count Good Substrings (思维)
- Codeforces Round #166 (Div. 2) D - Good Substrings
- Codeforces 451D Count Good Substrings(组合数学)
- Codeforces #258 (Div. 2) D. Count Good Substrings
- Codeforces Round #166 (Div. 2)---D. Good Substrings(字符串)
- Codeforces 451D Count Good Substrings (组合数)
- Codeforces Round #258 (Div. 2) D. Count Good Substrings
- Codeforces Round #258 (Div. 2)-D. Count Good Substrings
- Codeforces 451D - Count Good Substrings(组合数学)
- CodeForces 451 D.Count Good Substrings(水~)
- Jmeter的使用和分析监控
- 数据校验JSR
- 我的第一篇博客
- 解决Android中No resource found that matches android:TextAppearance.Material.Widget.Button.Inverse问题
- JDBC
- Codeforces 271D Good Substrings 暴力+Trie
- Android的postOnAnimation分析
- 防止回车键提交表单及键盘字母的code值
- mysql触发器
- 南阳oj 32 组合数
- spring4 注解 添加ContentNegotiatingViewResolver
- 怎么将两个表中树,拼成一个树(并创造一个顶级节点)还可以正常保存,下次修改的时候值还要正常的带出来?
- ffmpeg 3.2版本播放ts流正常,但是录制成为MP4的文件播放黑屏
- Scala for循环