#9802. [POI 2010] MOT-Monotonicity 2

    ID: 9802 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P3506动态规划 DP2010线段树树状数组POI(波兰)Special Judge

[POI 2010] MOT-Monotonicity 2

[POI 2010] MOT-Monotonicity 2

题目描述

This task is a harder version of task Monotonicity from the third stage of 17th Polish OI. It wasn't used in the contest itself.

For an integer sequence we define its monotonicity scheme as the sequence of symbols , or .

The symbol represents the relation between and .

For example, the monotonicity scheme of the sequence is .

We say that an integer sequence with monotonicity scheme , realizes another monotonicity scheme if for every it holds that .

In other words, the sequence can be obtained by repeating the sequence and removing appropriate suffix from that repetition.

For example, the sequence realizes each and every one of the following schemes:

as well as many others.

An integer sequence and a monotonicity scheme are given.

Your task is to find the longest subsequence () of the former that realizes the latter.

输入格式

The first line of the standard input holds two integers ![](http://main.edu.pl/images/OI17/mot-en-tex.27.png) and ![](http://main.edu.pl/images/OI17/mot-en-tex.28.png) (![](http://main.edu.pl/images/OI17/mot-en-tex.29.png), ![](http://main.edu.pl/images/OI17/mot-en-tex.30.png)), separated by a single space, denoting the lengths of the sequences ![](http://main.edu.pl/images/OI17/mot-en-tex.31.png) and monotonicity scheme ![](http://main.edu.pl/images/OI17/mot-en-tex.32.png) respectively.

The second input line gives the sequence , i.e, it holds integers separated by single spaces ().

Finally, the third lines gives the monotonicity scheme , i.e., it holds s…

输出格式

In the first line of the standard output your program should print out a single integer ![](http://main.edu.pl/images/OI17/mot-en-tex.40.png), the maximum length of a subsequence of ![](http://main.edu.pl/images/OI17/mot-en-tex.41.png) that realizes the scheme ![](http://main.edu.pl/images/OI17/mot-en-tex.42.png).

In the second line it should print out any such subsequence , separating its elements by single spaces.

7 3
2 4 3 1 3 5 3
 =
6
2 4 3 3 5 3

提示

(暂无提示) 标签: P3506|动态规划 DP|2010|线段树|树状数组|POI(波兰)|Special Judge

来源

P3506|[POI 2010] MOT-Monotonicity 2