-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1224 - DNA Prefix.cpp
78 lines (70 loc) · 1.25 KB
/
1224 - DNA Prefix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long int ll;
int mp[4];
ll mx;
struct node
{
node *next[5];
int endmark;
node()
{
for(int i = 0; i < 4; i++)
next[i] = NULL;
endmark = 0;
}
};
void Build_trie (char *str , int len , node *curr)
{
int t;
for(int i = 0; i < len; i++)
{
int id = mp[str[i]];
if(curr-> next[id] == NULL)
{
curr->next[id] = new node();
}
curr = curr->next[id];
++curr->endmark;
t = curr->endmark * (i + 1);
if(mx < t) mx = t;
}
}
void del(node *cur) {
for(int i=0; i < 4; i++)
if(cur -> next[i])
del(cur -> next[i]);
delete (cur);
}
void init()
{
mp['A'] = 0;
mp['C'] = 1;
mp['G'] = 2;
mp['T'] = 3;
}
int main()
{
init();
int tes, o = 0;
char s[50000];
scanf(" %d", &tes);
while(tes--)
{
o++;
node *root = new node();
int num;
scanf("%d", &num);
for(int i = 0; i < num; i++)
{
scanf(" %s" ,s);
Build_trie(s, strlen(s) , root);
}
printf("Case %d: %lld\n",o,mx);
del(root);
mx = 0;
}
}