CF2259A.Moo Language School

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Farmer John is trying to increase literacy rates in the United Cows of Farmer John (UCFJ). The UCFJ consists of nn fields and nk\frac{n}{k} farms (where nn is a multiple of kk), with each farm consisting of kk consecutive fields. In other words, the ii-th field is in the ⌈ik⌉\lceil \frac{i}{k} \rceil-th farm: Fields 1,2,…,k1, 2, \ldots, k are in the first farm, fields k+1,k+2,…,2kk+1, k+2, \ldots, 2k are in the second farm, etc.

Farmer John wants to build schools such that each farm has at least one school. However, some fields are owned by Farmer Nhoj, who will charge Farmer John extra to build a school there. Farmer John wants to know the minimum number of times that he would have to build a school on Farmer Nhoj's land in order to ensure that each farm has at least one school.

农夫约翰正试图提高“农夫约翰联合奶牛”(UCFJ)的识字率。UCFJ 由 nn 块田地和 nk\frac{n}{k} 个农场组成(其中 nn 是 kk 的倍数),每个农场恰好包含 kk 块连续的田地。换言之,第 ii 块田地属于第 ⌈ik⌉\lceil \frac{i}{k} \rceil 个农场:第 1,2,…,k1, 2, \ldots, k 块田地属于第一个农场,第 k+1,k+2,…,2kk+1, k+2, \ldots, 2k 块田地属于第二个农场,依此类推。

农夫约翰希望修建若干所学校,使得每个农场至少拥有一所学校。然而,部分田地归农夫诺杰(Farmer Nhoj)所有;若在这些田地上建校,农夫诺杰将向农夫约翰额外收费。农夫约翰想知道:为确保每个农场至少拥有一所学校,他最少需要在农夫诺杰的田地上建多少所学校?

输入格式

The first line of each input contains an integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains two integers nn and kk (1≤k≤n≤201 \leq k \leq n \leq 20, nn is a multiple of kk) — the number of fields and size of each farm.

The second line of each test case contains a binary string ss of length nn — the fields owned by Farmer Nhoj. If si=1s_i = 1, the ii-th field is owned by Farmer Nhoj. If si=0s_i = 0, the ii-th field is not owned by Farmer Nhoj.

每组输入的第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤k≤n≤201 \leq k \leq n \leq 20,且 nn 是 kk 的倍数)—— 分别表示田地总数以及每座农场的大小。

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss —— 表示 Farmer Nhoj 拥有的田地。若 si=1s_i = 1,则第 ii 块田地归 Farmer Nhoj 所有;若 si=0s_i = 0,则第 ii 块田地不属于 Farmer Nhoj。

输出格式

For each test case, output a single integer — the minimum number of times that Farmer John must build a school on Farmer Nhoj's land.

对于每个测试用例,输出一个整数——农夫约翰必须在农夫诺杰的土地上建造学校的最少次数。

输入输出样例

  • 输入#1

    6
    8 2
    10011100
    5 1
    11111
    8 4
    01111110
    5 1
    00101
    4 4
    1101
    4 4
    1111

    输出#1

    1
    5
    0
    2
    0
    1

说明/提示

For the first test case, we can build a school on the 22nd, 33rd, 55th, and 77th fields, and of those, only the 55th field is owned by Farmer Nhoj, meaning our answer is 11. It can be shown that this is the best possible answer.

For the second test case, Farmer Nhoj owns every field, and since we have to build 55 schools, we must build on Farmer Nhoj's land 55 times.

对于第一个测试用例,我们可以在第 22、第 33、第 55 和第 77 块田地上建造学校,其中仅有第 55 块田地属于 Farmer Nhoj,因此答案为 11。可以证明这是最优解。

对于第二个测试用例,Farmer Nhoj 拥有全部田地,而我们必须建造 55 所学校,因此必须在 Farmer Nhoj 的土地上建造 55 次。

输入解题思路,AI测评打分。不知道怎么写?

首页