uva 11488 - Hyper Prefix Sets(字典树)
2014-06-20 20:23
961 查看
H | Hyper Prefix Sets |
of these binary strings.
Input
First line of the input contains T(≤20) the number of test cases. Each of the test cases start with n(≤50000) the number of strings. Each of the next n lines contains a string containing only 0 and 1. Maximum length of each of these string is 200.
Output
For each test case output the maximum prefix goodness among all possible subsets of n binary strings.
Sample Input Output for Sample Input
4 4 0000 0001 10101 010 2 01010010101010101010 11010010101010101010 3 010101010101000010001010 010101010101000010001000 010101010101000010001010 5 01010101010100001010010010100101 01010101010100001010011010101010 00001010101010110101 0001010101011010101 00010101010101001 | 6 20 66 44 |
#include <iostream> #include <cstdio> #include <vector> #include <cstring> #include <string> using namespace std; struct edge{ int u , v , letter , sum , dep; edge(int a = 0 , int b = 0 , int c = 0 , int d = 0 , int f = 0){ u = a , v = b , letter = c , sum = d , dep = f; } }; vector<edge> e; vector<int> head , next; int ans; void add(int u , int v , int letter , int sum , int dep){ e.push_back(edge(u , v , letter , sum , dep)); next.push_back(head[u]); head[u] = next.size()-1; head.push_back(-1); } void addLibrary(string s){ int u = 0 , index = 0; while(index < s.length()){ int Next = head[u]; while(Next != -1){ if(e[Next].letter == s[index]-'0') break; Next = next[Next]; } if(Next == -1) break; e[Next].sum++; index++; u = e[Next].v; } while(index < s.length()){ add(u , head.size() , s[index]-'0' , 1 , index+1); index++; u = head.size()-1; } } void initial(){ e.clear(); next.clear(); head.clear(); head.push_back(-1); ans = 0; } void readcase(){ string s; int n; scanf("%d" , &n); getchar(); while(n--){ cin >> s; //cout <<"+"<<s<<endl; addLibrary(s); } for(int i = 0; i < e.size(); i++){ if(e[i].sum*e[i].dep > ans) ans = e[i].sum*e[i].dep; } printf("%d\n" , ans); } int main(){ int t; scanf("%d" , &t); while(t--){ initial(); readcase(); } return 0; }
相关文章推荐
- UVA 11488 Hyper Prefix Sets (字典树)
- UVa 11488 Hyper Prefix Sets(字典树)
- Uva 11488 Hyper Prefix Sets 字典树
- UVa 11488 Hyper Prefix Sets 字典树基础题
- Hyper Prefix Sets UVA - 11488 字典树裸题
- uva 11488 - Hyper Prefix Sets(字典树)
- UVA 11488 Hyper Prefixs Sets(字典树Trie)
- UVA 11488 Hyper Prefix Sets(字典树)
- UVA11488——Hyper Prefix Sets(字典树,最长前缀)
- UVA 11488 Hyper Prefix Sets 字典树
- UVa 11488 - Hyper Prefix Sets
- Hyper Prefix Sets - UVa 11488 Trie树
- UVa11488-Hyper Prefix Sets(trie树)
- UVA 11488-Hyper Prefix Sets(Trie)
- UVA 11488 Hyper Prefix Sets(trie的应用)
- UVa 11486 Hyper Prefix Sets 字典树裸题
- Uva-11488-Hyper Prefix Sets
- UVa 11488 - Hyper Prefix Sets (Trie)
- UVa11488 Hyper Prefix Sets
- UVA 11488 Hyper Prefix Sets (Trie)