Codeforces Round 160 (Div. 1)
D
Maxim and Increasing Subsequence
Codeforces
2600
原题
← CE →
翻译中…

Maxim loves sequences, especially those that strictly increase. He is wondering, what is the length of the longest increasing subsequence of the given sequence $*a*$?

翻译中…

Sequence $*a*$ is given as follows:

翻译中…
  • the length of the sequence equals $*n* × *t*$;
  • image $(1 ≤ *i* ≤ *n* × *t*)$, where operation image means taking the remainder after dividing number $*x*$ by number $*y*$.
翻译中…

Sequence $*s*_{1},  *s*_{2},  ...,  *s*_{*r*}$ of length $*r*$ is a subsequence of sequence $*a*_{1},  *a*_{2},  ...,  *a*_{*n*}$, if there is such increasing sequence of indexes $*i*_{1}, *i*_{2}, ..., *i*_{*r*}$ $(1  ≤  *i*_{1}  <  *i*_{2}  < ...   <  *i*_{*r*}  ≤  *n*)$, that $*a*_{*i*_{*j*}}  =  *s*_{*j*}$. In other words, the subsequence can be obtained from the sequence by crossing out some elements.

翻译中…

Sequence $*s*_{1},  *s*_{2},  ...,  *s*_{*r*}$ is increasing, if the following inequality holds: $*s*_{1} < *s*_{2} <  ... <  *s*_{*r*}$.

翻译中…

Maxim have $*k*$ variants of the sequence $*a*$. Help Maxim to determine for each sequence the length of the longest increasing subsequence.

翻译中…

Input

翻译中…

The first line contains four integers $*k*$, $*n*$, $*maxb*$ and $*t*$ $(1 ≤ *k* ≤ 10; 1 ≤ *n*, *maxb* ≤ 10^{5}; 1 ≤ *t* ≤ 10^{9}; *n* × *maxb* ≤ 2·10^{7})$. Each of the next $*k*$ lines contain $*n*$ integers $*b*_{1}, *b*_{2}, ..., *b*_{*n*}$ $(1 ≤ *b*_{*i*} ≤ *maxb*)$.

翻译中…

Note that for each variant of the sequence $*a*$ the values $*n*$, $*maxb*$ and $*t*$ coincide, the only arrays $*b*$s differ.

翻译中…

The numbers in the lines are separated by single spaces.

翻译中…

Output

翻译中…

Print $*k*$ integers — the answers for the variants of the sequence $*a*$. Print the answers in the order the variants follow in the input.

翻译中…

样例

Input #1
3 3 5 2
3 2 1
1 2 3
2 3 1
Output #1
2
3
3
InputCopy OutputCopy
题目信息
题号
261D
时间限制
6 s
内存限制
256 MB
标签
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。