Official

Ex - Hakata Editorial by en_translator


Let \(N\) be the number of distinct palindromes in \(S\), then in fact \(N\leq |S|\) holds.
This is because, when a character is appended to a string, no more than one palindrome is newly obtained.

Consider vertices corresponding to each palindrome, and add a directed edge between two palindromes if one is a substring of the other.
Then, the problem can be expressed as follows.

Given a DAG (Directed Acyclic Graph) with \(N\) vertices, you will choose some of the vertices.
However, you cannot choose two vertices such that there is a path between them.
How many vertices can be chosen at most?

In this graph, when there are edges \(i\rightarrow j, j \rightarrow k\), then there is always another edge \(i\rightarrow k\), so by Dilworth’s theorem, it can be rephrased as follows.

Given a DAG with \(N\) vertices, find the size of minimum path cover.

This problem can be solved as a maximum-matching problem on a bipartite graph with \(N\) vertices on each side in which there is an edge from Vertex \(i\) in the left to Vertex \(j\) in the right if there is an edge \(i\rightarrow j\) in the original graph.

Therefore, the problem has been solved.

posted:
last update: