洞察探讨小游戏SDK接入的最佳实践以及对企业跨平台开发的优势
847
2022-10-03
Codeforces 919 D. Substring (记忆化搜索)
Description
You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path’s value as the number of the most frequently occurring letter. For example, if letters on a path are “abaca”, then the value of that path is 3. Your task is find a path whose value is the largest.
Input
The first line contains two positive integers n, m (1 ≤ n, m ≤ 300 000), denoting that the graph has n nodes and m directed edges.The second line contains a string s with only lowercase English letters. The i-th character is the letter assigned to the i-th node.Then m lines follow. Each line contains two integers x, y (1 ≤ x, y ≤ n), describing a directed edge from x to y. Note that x can be equal to y and there can be multiple edges between x and y. Also the graph can be not connected.
Output
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
Examples input
5 4abaca1 21 33 44 5
Examples output
3
题意
在图中找一条路径,满足该路径上某字母的出现频率最高,输出该字母的出现次数。(图中可能存在自环以及重边)
思路
记忆化搜索, dp[o][ch] d p [ o ] [ c h ] 代表节点 o o 及以下字符 chch
tarjan 判环,注意存在自环情况。
AC 代码
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~