【CodeForces 271D】Good Substrings
【链接】 我是链接,点我呀:)
【题意】
【题解】
字典树
我们可以两重循环(i,j)
来枚举所有的子串
即i=1,j=1,2,3...
i=2,j = 2,3,4,..
于是我们在i变化的时候(就是j层循环完了,i要执行i+1的时候
令cur=字典树的root
然后沿着字典树往下走。
遇到没有走过的位置,就说明我们找到了一个之前没有碰到的子串。
那么我们就++tot,按照字典树的规则,创建一个新的节点。
否则如果有这个节点,那么就接着往下走就好,说明这个子串s[i..j]之前出现过
然后如果特殊字母>=k了,那么就直接break即可。
最后字典树的节点个数就是符合要求的子串个数.
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
using namespace std;
const int N = 1500*1500;
string s;
string dic;
int ch[N+10][26];
int k,tot,root = 1;
int main()
{
#ifdef LOCAL_DEFINE
freopen("rush.txt","r",stdin);
#endif // LOCAL_DEFINE
ios::sync_with_stdio(0),cin.tie(0);
cin >> s;
cin >> dic;
cin >> k;
tot = 1;
rep1(i,0,(int)s.size()-1){
int cur = root;
int cnt = 0;
rep1(j,i,(int)s.size()-1){
if (dic[s[j]-'a']=='0') cnt++;
if (cnt>k) break;
if (ch[cur][s[j]-'a']==0)ch[cur][s[j]-'a']=++tot;
cur = ch[cur][s[j]-'a'];
}
}
cout<<tot-1<<endl;
return 0;
}
【CodeForces 271D】Good Substrings的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【Codeforces 258D】 Count Good Substrings
[题目链接] http://codeforces.com/contest/451/problem/D [算法] 合并后的字符串一定是形如"ababa","babab&qu ...
- 【19.46%】【codeforces 551B】ZgukistringZ
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 766C】Mahmoud and a Message
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- C语言遍历文件和文件夹——————【Badboy】
[cpp] #include #include #include #include #include #include #include #define MAX_PATH_LENGTH 512 #de ...
- h5-8 canvas
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- [HTML5] 新标签解释及用法
转自:http://www.cnblogs.com/yuzhongwusan/archive/2011/11/17/2252208.html HTML 5 是一个新的网络标准,目标在于取代现有的 HT ...
- [JXOI 2018] 守卫 解题报告 (DP)
interlinkage: https://www.luogu.org/problemnew/show/P4563 description: solution: 注意到对于范围$[l,r]$,$r$这 ...
- JS——BOM操作(基本用法与实现:open()、close()、scrollTop等了解)
(1)window.open() 定义和用法 open() 方法用于打开一个新的浏览器窗口或查找一个已命名的窗口 语法 window.open(URL,name,specs,replace) [默认填 ...
- HDU1412 {A} + {B}
2019-05-17 10:15:01 每个元素之间有一个空格隔开. 每行最后一的元素后面没有空格,区别于HDU人见人爱A - B 注意使用STL的时候要清空 . a.clear(); #inclu ...
- 如何运用docker配合python开发
在网络层,互联网提供所有应用程序都要使用的两种类型的服务,尽管目前理解这些服务的细节并不重要,但在所有TCP/IP概述中,都不能忽略他们: 无连接分组交付服务(Connectionless Packe ...
- sublime3 install python3
链接地址:https://blog.csdn.net/Ti__iT/article/details/78830040
- [Offer收割]编程练习赛34
共同富裕 显然每次选最大的数字,其余的加一.也可以理解为每次选一个最大的数字减一,直到所有数字都变成最小的数字为止. #include<stdio.h> #include<strin ...
- 基于jQuery封装一个瀑布流插件
/*封装一个瀑布流插件*/ (function($){ $.fn.WaterFall = function(){ /*这是你初始化 调用这个方法的时候的 那个jquery选着到的dom对象 this* ...