编程介的小学生 2019-01-14 16:09 采纳率: 20.5%
浏览 220
已采纳

计算子数组最大和的一个问题,是不是需要DP的算法,采用C语言解决的思路是什么的?

Problem Description
Word's combination is an interesting thing.
Given a set of words S={s1, s2, ..., sn}, where si is a word only consists lowercase letter and its length is less than 50. When si merges in a text, its effect on reader's mood is both positive and negative. A word's positive effect is measured in love level li and negative effect is in hate level hi.
At the same time, given a set paragraph P={P1, P2, ..., Pn} and Pj is a string whose length is less than 1000. For each word si in S, there is two conditions in Pj as follows:
Related : si is a substring of Pj, and li units of love level is added to Pj, if si occurs several times in Pj, every occurrence is counted.
Unrelated : si never occurs in Pj and this condition bring Pj nothing.
Text T is defined as a subset of P. T's love level is defined as sum of Pj's love level where Pj belongs to T minus words?hate level. Because a strange psychology phenomenon, hate level of a word which occurs in T is only counted once no matter how many times it occurs.
Given the set of S and P, writing robot's job is to select a subset T to maximum the love level.

Input
The first line of the input contains a single integer T (1 ≤ T ≤ 15), the number of test cases. Then T cases follow.
First line of each case contains 2 integers, S, P. (1≤S, P≤150), then S lines follows, each line contains 2 integers, li, hi, (1≤li≤100, 1≤hi≤1000), and a string si with length less than 50. Next P lines, each contains a string Pi with length less than 1000. It guarantees that the answer will not exceed 32-bit signed integer.

Output
For the x-th test case, print "Case x: " and maximum T's profit in a line.

Sample Input
2
3 2
2 2 hit
1 2 it
3 1 song
hitman
singasong
2 2
2 3 ab
1 6 ba
ababab
bababa

Sample Output
Case 1: 2
Case 2: 6

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-12-31 02:09
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题