外星聯絡[trie樹]
每個點先後建trie樹 , 然後先dfs "0" 兒子 , 再dfs"1" 兒子 , 這樣對應字典序
如果cnt<=1 直接return , 因為後面的也都不可能>1了
#include<bits/stdc++.h> #define N 3050 using namespace std; char s[N]; int n,tot=1,t[N*N][2],cnt[N*N]; void build(int st){ int now=1; for(int i=st;i<=n;i++){ int ch=s[i]-'0' , &res=t[now][ch]; if(!res) res = ++tot; cnt[res]++ , now = res; } } void dfs(int u){ if(cnt[u]<=1) return; printf("%d\n",cnt[u]); dfs(t[u][0]) , dfs(t[u][1]); } int main(){ scanf("%d%s",&n,s+1); for(int i=1;i<=n;i++) build(i); dfs(t[1][0]) , dfs(t[1][1]); return 0; }
相關推薦
外星聯絡[trie樹]
傳送門 每個點先後建trie樹 , 然後先dfs "0" 兒子 , 再dfs"1" 兒子 , 這樣對應字典序 如果cnt<=1 直接return , 因為後面的也都不可能>1了 #include<bits/stdc++.h> #define N 3050 us
bzoj 2251[2010Beijing Wc]外星聯絡
www. href gpo max line lin cst clu 全部 題目鏈接 bzoj2251 [2010Beijing Wc]外星聯絡 題解 求出height數組後 對與一個串的存在性 畫出圖來好理解一些,emmmmm,我就不畫了 height[i+1]的值比he
bzoj 2251[2010Beijing Wc](luogu 4341)外星聯絡
演算法:(trie的性質&&字串性質)/(字尾陣列+貪心) 難度:NOIP+ 首先你需要知道一條關於字串的性質:一個字串所有後綴的所有字首就能代表該串的所有子串! 當然了
[BZOJ2251/BJWC2010]外星聯絡
rom clas sort NPU des mes int ati wol Description 小 P 在看過電影《超時空接觸》(Contact)之後被深深的打動,決心致力於尋找外星人的事業。於是,他每天晚上都爬在屋頂上試圖用自己的收音機收聽外星人發來的信息。雖然他收聽
HDU1251 統計難題 【trie樹】
courier ava 自己的 while onos ets ctrl pan alloc 統計難題 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Other
【BZOJ4567】[Scoi2016]背單詞 Trie樹+貪心
字母 如果 ems scanf 序號 data scan name rdquo 【BZOJ4567】[Scoi2016]背單詞 Description Lweb 面對如山的英語單詞,陷入了深深的沈思,“我怎麽樣才能快點學完,然後去玩三國殺呢?&rdquo
淺談 trie樹 及事實上現
空間換時間 字符串 arc com post pre 1.5 dsm back 定義:又稱字典樹,單詞查找樹或者前綴樹,是一種用於高速檢索的多叉樹結構。 如英文字母的字典樹是一個26叉樹,數字的字典樹是一個10叉樹。 核心思想:是空間換時間.利用字符串的公共前綴來
wikioi 1306 機智Trie樹
rip margin rac 1.5 ott 增加 block 範圍 code 題目描寫敘述 Description 看廣播操無聊得非常~你有認為嗎?在看廣播操一波又一波的人潮湧過再退去。認為非常沒意思……於是,偶們的大神犇JHT發明了一個及其
【bzoj3281】最大異或和 可持久化Trie樹
log pac 序列 str char s pan pri scan bool 題目描述 給定一個非負整數序列 {a},初始長度為 N。 有M個操作,有以下兩種操作類型:1、A x:添加操作,表示在序列末尾添加一個數 x,序列的長度 N+1。2、Q l r x
信息檢索——初識Trie樹
操作 font -c 字符 get 排序 span strong trietree 1、概述 Trie樹( /tri:/ ),又稱前綴樹、字典樹,是種快速檢索的多叉樹結構, Trie樹的基本性質可以歸納為: (1)根節點不包含字符,除根節點意外每個節點只包含一個字
【BZOJ3689】異或之 堆+可持久化Trie樹
ace iostream 持久化 sof stream tro urn org cst 【BZOJ3689】異或之 Description 給定n個非負整數A[1], A[2], ……, A[n]。對於每對(i, j)滿足1 <=
【bzoj4212】神牛的養成計劃 Trie樹+可持久化Trie樹
dna sid -- ihe for 物體 ota span xsd 題目描述 Hzwer成功培育出神牛細胞,可最終培育出的生物體卻讓他大失所望...... 後來,他從某同校女神 牛處知道,原來他培育的細胞發生了基因突變,原先決定神牛特征的基因序列都被破壞了,神牛hzw
hihocoder--hiho一下第二周(Trie樹)
英文 -h 字符 modal data- clas 接下來 小寫 nbsp 時間限制:10000ms 單點時限:1000ms 內存限制:256MB 描述 小Hi和小Ho是一對好朋友,出生在信息化社會的他們對編程產生了莫大的興趣,他們約定好互相幫助,在編程
trie樹查找和hash查找比較(大量數據)
stdlib.h emp lib ras eno strlen oid ack std trie樹代碼 #include<iostream> #include<stdio.h> #include<iostream> #include&l
[POJ 1204]Word Puzzles(Trie樹暴搜&AC自己主動機)
cloc produce cte owin you dsm queue pos cti Description Word puzzles are usually simple and very entertaining for all ages. They are
HDU 4825 Trie樹 異或樹!
釋放內存 情況 %d 前綴 out ble 證明 rip -s Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total Submis
[SPOJ COT3] SG函數 Trie樹 線段樹合並
swa 線段 std line etc 分析 eight sin stdout 題目 分析 實現 #include <cstdio> #include <cstring> #include <cstdlib>
Trie樹(字典樹)(1)
stdio.h public ctu 哈希 pac 索引 cas proc ren Trie樹。又稱字典樹,單詞查找樹或者前綴樹,是一種用於高速檢索的多叉樹結構。 Trie樹與二叉搜索樹不同,鍵不是直接保存在節點中,而是由節點在樹中的位置決定。
【bzoj3217】ALOEXT 替罪羊樹套Trie樹
uil 重新 return 等於 開始 space 無法 last esp 題目描述 taorunz平時最喜歡的東西就是可移動存儲器了……只要看到別人的可移動存儲器,他總是用盡一切辦法把它裏面的東西弄到手。 突然有一天,taorunz來到了一
XJOI 異或 (Trie樹)
log for 為我 its 區間 scanf tle ear name 這題對我來說真是一塊大蛋糕,又是一座大山 大蛋糕是因為算法很好胡 大山是因為我實在是太菜 然後我就在考場上續了兩個小時 /-------------------------------