CF1811G1.Vlad and the Nice Paths (easy version)
提高+/省选-
通过率:0%
时间限制:5.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an easy version of the problem, it differs from the hard one only by constraints on n and k.
Vlad found a row of n tiles and the integer k. The tiles are indexed from left to right and the i-th tile has the color ci. After a little thought, he decided what to do with it.
You can start from any tile and jump to any number of tiles right, forming the path p. Let's call the path p of length m nice if:
- p can be divided into blocks of length exactly k, that is, m is divisible by k;
- cp1=cp2=…=cpk;
- cpk+1=cpk+2=…=cp2k;
- …
- cpm−k+1=cpm−k+2=…=cpm;
Your task is to find the number of nice paths of maximum length. Since this number may be too large, print it modulo 109+7.
这是一个该问题的简单版本,它与困难版本的唯一区别在于对 n 和 k 的约束不同。
弗拉德发现了一排 n 块瓷砖以及一个整数 k。瓷砖从左到右编号,第 i 块瓷砖的颜色为 ci。稍作思考后,他决定如何处理这排瓷砖。
你可以从任意一块瓷砖出发,并向右跳跃任意数量的瓷砖,从而形成一条路径 p。若路径 p(长度为 m)满足以下条件,则称其为优美的路径(nice path):
- p 可被划分为若干个长度恰好为 k 的块,即 m 能被 k 整除;
- cp1=cp2=…=cpk;
- cpk+1=cpk+2=…=cp2k;
- …
- cpm−k+1=cpm−k+2=…=cpm;
你的任务是求出最长优美路径的条数。由于该数目可能过大,请输出其对 109+7 取模的结果。
输入格式
The first line of each test contains the integer t (1≤t≤104) — the number of test cases in the test.
The first line of each test case contains two integers n and k (1≤k≤n≤100) — the number of tiles in a row and the length of the block.
The second line of each test case contains n integers c1,c2,c3,…,cn (1≤ci≤n) — tile colors.
It is guaranteed that the sum of n3 over all test cases does not exceed 5⋅106.
每个测试的第一行包含一个整数 t(1≤t≤104)—— 表示该测试中测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 k(1≤k≤n≤100)—— 分别表示一行中瓷砖的数量以及块的长度。
每个测试用例的第二行包含 n 个整数 c1,c2,c3,…,cn(1≤ci≤n)—— 表示瓷砖的颜色。
保证所有测试用例的 n3 之和不超过 5⋅106。
输出格式
Print t numbers, each of which is the answer to the corresponding test case — the number of nice paths of maximum length modulo 109+7.
输出 t 个数字,每个数字对应一个测试用例的答案——即最长“好路径”的数量对 109+7 取模的结果。
输入输出样例
输入#1
5 5 2 1 2 3 4 5 7 2 1 3 1 3 3 1 3 11 4 1 1 1 1 1 1 1 1 1 1 1 5 2 1 1 2 2 2 5 1 1 2 3 4 5
输出#1
1 4 165 3 1
说明/提示
In the first sample, it is impossible to make a nice path with a length greater than 0.
In the second sample, we are interested in the following paths:
- 1→3→4→5
- 2→4→5→7
- 1→3→5→7
- 1→3→4→7
In the third example, any path of length 8 is nice.
在第一个样例中,无法构造长度大于 0 的优美路径。
在第二个样例中,我们关注以下路径:
- 1→3→4→5
- 2→4→5→7
- 1→3→5→7
- 1→3→4→7
在第三个样例中,任意长度为 8 的路径都是优美路径。
输入解题思路,AI测评打分。不知道怎么写?