Score : 625 points
问题陈述
给定 N 个字符串 S1,S2,…,SN,它们由小写英文字母组成,以及 N 个正整数 A1,A2,…,AN。
如果集合 T 是 {1,2,…,N} 的一个子集,并且对于 T 中的任意两个不同的元素 i,j,Si 不是 Sj 的子串,则称 T 为一个好集合。
找出一个好集合 T 的 i∈T∑Ai 的最大可能值。
什么是子串?字符串 S 的一个子串是通过从 S 的开头删除零个或多个字符,以及从 S 的结尾删除零个或多个字符得到的字符串。例如,ab 是 abc 的一个子串,但 ac 不是 abc 的子串。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given N strings S1,S2,…,SN consisting of lowercase English letters and N positive integers A1,A2,…,AN.
A subset T of {1,2,…,N} is called a good set if there is no pair i,j∈T(i=j) such that Si is a substring of Sj.
Find the maximum possible value of i∈T∑Ai for a good set T.
What is a substring? A substring of a string S is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of S. For example, ab is a substring of abc, but ac is not a substring of abc.
Constraints
- 1≤N≤100
- Si is a string consisting of lowercase English letters.
- 1≤∣Si∣
- ∣S1∣+∣S2∣+…+∣SN∣≤5000
- 1≤Ai≤109
The input is given from Standard Input in the following format:
N
S1
S2
⋮
SN
A1 A2 … AN
Output
Print the answer.
4
atcoder
at
coder
code
5 2 3 4
Sample Output 1
6
The possible good sets T and their corresponding i∈T∑Ai are as follows:
- T={1}: i∈T∑Ai=5
- T={2}: i∈T∑Ai=2
- T={3}: i∈T∑Ai=3
- T={4}: i∈T∑Ai=4
- T={2,3}: i∈T∑Ai=5
- T={2,4}: i∈T∑Ai=6
The maximum among them is 6, so print 6.
10
abcd
abc
ab
a
b
c
d
ab
bc
cd
100 10 50 30 60 90 80 70 40 20
Sample Output 2
260