这道题的大意就是,给定一个递增的序列,然后从中挑选出几个,使得相邻的两个都不互质(即存在公共因子)。
问最长的能多长。
思路:用一个vector数组,将每个数的因子存起来,然后用一个dp数组,存以因子i结尾的最长的长度。一个数每一次都算出来所有因子中最大的以某个因子结尾的长度更新所有的因子。这一点是比较难想的。于是就这样就能够进行转移。
具体看代码:
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good.
Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three conditions:
-
<