UVa 11488 Hyper Prefix Sets(字典树)
来源:互联网 发布:微信淘口令淘宝打不开 编辑:程序博客网 时间:2024/05/16 19:32
字典树每个节点维护这个节点的深度和到达这里的字符串数量,用这两个的乘积维护答案即可。
代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int idx(char c){return c-'0';}struct node{int bt[2];int num;int deep;}G[1000000];int sz=1;int res=0;void Insert(char s[]){int len=strlen(s);int cur=0;for(int i=0;i<len;i++){int k=idx(s[i]);if(!G[cur].bt[k]){G[cur].bt[k]=sz;G[sz].deep=G[cur].deep+1;sz++;}cur=G[cur].bt[k];G[cur].num++;res=max(res,G[cur].num*G[cur].deep);}}int main(){int T;scanf("%d",&T);while(T--){int N;scanf("%d",&N);sz=1;res=0;memset(G,0,sizeof(G));for(int i=0;i<N;i++){char s[205];scanf("%s",s);Insert(s);}printf("%d\n",res);}return 0;}/*440001000010101010201010101010101110101010101013010101010101010010101010101000010101010101010*/
0 0
- uva 11488 - Hyper Prefix Sets(字典树)
- UVA 11488 Hyper Prefix Sets 字典树
- Uva 11488 Hyper Prefix Sets 字典树
- uva 11488 - Hyper Prefix Sets(字典树)
- UVa 11488 Hyper Prefix Sets(字典树)
- UVA 11488 Hyper Prefix Sets(字典树)
- UVa 11488 Hyper Prefix Sets 字典树基础题
- UVA 11488,Hyper Prefix Sets,Trie树
- Hyper Prefix Sets - UVa 11488 Trie树
- uva 11488 - Hyper Prefix Sets(Trie)
- UVa 11488 - Hyper Prefix Sets (Trie)
- UVA 11488-Hyper Prefix Sets(trie树+DFS)
- Uva-11488-Hyper Prefix Sets
- UVa:11488 Hyper Prefix Sets
- UVA - 11488 Hyper Prefix Sets
- uva 11488 Hyper Prefix Sets
- UVa 11488 - Hyper Prefix Sets
- UVA 11488 Hyper Prefix Sets
- SSH 之 Spring的源码(一)——Bean加载过程
- MFC控件:listctrl使用方法总结
- maven打包报错:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test
- C++类和动态内存分配
- LeetCode OJ Wildcard Matching
- UVa 11488 Hyper Prefix Sets(字典树)
- LeetCode OJ Permutations II
- OC学习小结之protocol
- LeetCode OJ Jump Game II
- 当初我未嫁,你未娶。你干什么去了?
- LeetCode OJ Permutations
- LeetCode OJ Combination Sum II
- LeetCode OJ Combination Sum
- 我对编程的理解