CFrou687 B. Repainting Street【枚举】

汤姆是一位画家,负责将一条街道上的房屋重新粉刷,使其颜色一致以达到美观效果。他的工作能力限制他每天最多可以连续粉刷k座房屋。题目给出每个房屋的初始颜色和k值,求最少需要多少天来完成任务。输入包含测试用例数量,每个用例包括房屋数量n,每天最大粉刷房屋数k,以及每座房屋的初始颜色。输出为每个测试用例所需的最少天数。
摘要由CSDN通过智能技术生成

There is a street with n houses in a line, numbered from 1 to n. The house i is initially painted in color ci. The street is considered beautiful if all houses are painted in the same color. Tom, the painter, is in charge of making the street beautiful. Tom’s painting capacity is defined by an integer, let’s call it k.

On one day, Tom can do the following repainting process that consists of two steps:

He chooses two integers l and r such that 1≤l≤r≤n and r−l+1=k.
For each house i such that l≤i≤r, he can either repaint it with any color he wants, or ignore it and let it keep its current color.
Note that in the same day Tom can use different colors to repaint different houses.

Tom wants to know the minimum number of days needed to repaint the street so that it becomes beautiful.

Input
The first line of input contains a single integer t (1≤t≤104), the number of test cases. Description of test cases follows.

In the first line of a test case description there are two integers n and k (1≤k≤n≤105).

The second line contains n space-separated integers. The i-th of these integers represents ci (1≤ci≤100), the color which house i is initially painted in.

It is guaranteed that the sum of n over all test cases does not exceed 105.

Output
Print t lines, each with one integer: the minimum number of days Tom needs to make the street beautiful for each test case.

Example
inputCopy
3
10 2
1 1 2 2 1 1 2 2 2 1
7 1
1 2 3 4 5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值