bzoj 2251: 外星联络 后缀Trie
题目大意
题解
本来以为这道题应该从01序列的性质入手
结果就想歪了
等自己跳出了01序列这个思维
就马上看到了一颗Trie树。。。
这道题的较难思考的地方在于无法确定出每个字符串的字典序
所以我们想到了和字典序有关的东西sort+string字典树
我们知道所有后缀的所有前缀一定能取到所有字串
字典树的dfs序列得到的dfs序是按照字典序排列的
所以我们可以理所当然地用字典树来搞这个东西
Code
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 3010;
int ch[maxn*maxn][2];
int num[maxn*maxn],nodecnt,n;
char s[maxn];
inline void insert(int i){
int nw = 0;
for(;i<n;++i){
if(ch[nw][s[i]-'0'] == 0) ch[nw][s[i]-'0'] = ++nodecnt;
nw = ch[nw][s[i] - '0'];
++num[nw];
}
}
inline void dfs(int u){
if(num[u] > 1) printf("%d\n",num[u]);
if(ch[u][0]) dfs(ch[u][0]);
if(ch[u][1]) dfs(ch[u][1]);
}
int main(){
read(n);scanf("%s",s);
for(int i=0;i<n;++i) insert(i);
dfs(0);
getchar();getchar();
return 0;
}
bzoj 2251: 外星联络 后缀Trie的更多相关文章
- bzoj 2251: [2010Beijing Wc]外星联络 后缀数组
2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 424 Solved: 232[Submit][ ...
- 【BZOJ-2251】外星联络 后缀数组 + 暴力
2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 670 Solved: 392[Submit][ ...
- [BJWC2010] 外星联络 - 后缀数组
[BJWC2010] 外星联络 Description 求一个 \(01\) 串中所有重复出现次数大于 \(1\) 的子串所出现的次数,按照字典序排序输出. Solution 预处理出后缀数组和高度数 ...
- 【BZOJ2251】[2010Beijing Wc]外星联络 后缀数组
[BZOJ2251][2010Beijing Wc]外星联络 Description 小 P 在看过电影<超时空接触>(Contact)之后被深深的打动,决心致力于寻找外星人的事业.于是, ...
- BZOJ2251 [2010Beijing Wc]外星联络 后缀数组 + Height数组
Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in", "r", stdin ...
- [bzoj2251][2010Beijing Wc]外星联络——后缀数组+暴力求解
Brief Description 找到 01 串中所有重复出现次数大于 1 的子串.并按字典序输出他们的出现次数. Algorithm Design 求出后缀数组之后,枚举每一个后缀,对于每个后缀从 ...
- BZOJ 2251: [2010Beijing Wc]外星联络
2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 795 Solved: 477[Submit][ ...
- 2251: [2010Beijing Wc]外星联络
2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 801 Solved: 481[Submit][ ...
- BZOJ_2251_[2010Beijing Wc]外星联络_后缀数组
BZOJ_2251_[2010Beijing Wc]外星联络_后缀数组 Description 小 P 在看过电影<超时空接触>(Contact)之后被深深的打动,决心致力于寻 找外星人的 ...
随机推荐
- 如何在cmd中启动redis
首先要指定redis安装的目录,然后输入: redis-server.exe redis.windows.conf 如果成功,则会出现redis的标志,失败的话 请转帖到: http://www.cn ...
- C++成员不通过对象调用的直接调用写法
C++成员不通过对象调用(.或->方式)的另类(C式)调用写法 #include <iostream> using namespace std; /* 我们知道,成员函数和普通函数最 ...
- 为什么阿里巴巴不建议在for循环中使用"+"进行字符串拼接
字符串,是Java中最常用的一个数据类型了.关于字符串的知识,作者已经发表过几篇文章介绍过很多,如: Java 7 源码学习系列(一)--String 该如何创建字符串,使用" " ...
- 摩托罗拉SE955 One Discrete Length,Two Discrete Lengths,Length Within Range 相关解释
motorola scanner datasheet相关解释(下面通过Simple Serial Interface(SSI)进行设置,非扫描官方datasheet的设置条码): One Discre ...
- CGI FASTCGI php-fpm
CGI(Common Gateway Interface) CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工 ...
- python实现接口测试到unittest框架集成
接口测试是面试测试岗位基本都会问到的问题,但是对于一些刚做测试的小伙伴可能并不是很熟悉,也有可能了解接口测试,但是完全不知道接口自动化怎么做.下面我们大概介绍一下. 首先我们需要知道接口自动化测试的目 ...
- 【selenium+python】之Python Flask 开发环境搭建(Windows)
一.先安装python以及pip 二.其次, Python的虚拟环境安装: 在github上下载https://github.com/pypa/virtualenv/tree/master zip文 ...
- android 在githup中的资源整理(转)
1.Github开源Android组件资源整理(一) 个性化控件(View) 2.Github开源Android组件资源整理(二)ActionBar和Menu 3. Github开源Android组件 ...
- js document.queryCommandState() 各个参数
命令标识符 2D-Position 允许通过拖曳移动绝对定位的对象. AbsolutePosition 设定元素的 position 属性为“absolute”(绝对). BackColor 设置或获 ...
- jquery 滚动效果插件
1.css <style> .fl { float: left; } .slider0 img { display: block; width:100px; padding: 2px; } ...