CF2173A.Sleeping Through Classes

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have nn classes today, which are numbered from 11 to nn.

The classes are described by a binary string∗^{\text{∗}} ss of length nn. We call class ii important if and only if $s_i = \mathtt 1 $. For each important class, you must stay awake and listen to it.

You are very tired and wish to sleep through as many classes as possible. However, falling asleep takes time. If you listen to an important class ii, then you cannot fall asleep for the next kk classes, i.e., you must also stay awake in classes i+1,i+2,…,i+ki+1, i+2, \ldots, i+k (or until the end of the day, if fewer than kk classes remain).

For classes that are not important, you may sleep through them unless the rule above forces you to stay awake.

Your task is to find out the maximum number of classes you can sleep through today.

∗^{\text{∗}}A binary string is a string where each character is either 0\mathtt{0} or 1\mathtt{1}.

你今天有 nn 节课,编号从 11 到 nn。

这些课程由一个长度为 nn 的二进制字符串∗^{\text{∗}} ss 描述。当且仅当 si=1s_i = \mathtt{1} 时,我们称第 ii 节课为重要课程;对于每节重要课程,你都必须保持清醒并认真听讲。

你非常疲惫,希望尽可能多地睡过一些课程。然而,入睡需要时间:如果你听了某节重要课程 ii,那么接下来的 kk 节课你都无法入睡,即你必须在课程 i+1,i+2,…,i+ki+1, i+2, \ldots, i+k(若剩余课程不足 kk 节,则至当天结束为止)中继续保持清醒。

对于非重要课程(即 si=0s_i = \mathtt{0} 的课程),你本可以睡过它们,但若上述规则强制你保持清醒,则你仍需清醒。

你的任务是求出你今天最多能睡过多少节课。

∗^{\text{∗}}二进制字符串是指每个字符均为 0\mathtt{0} 或 1\mathtt{1} 的字符串。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains two integers nn and kk (1≤n,k≤1001 \le n, k \le 100).

The second line of each test case contains the string ss of length nn (si=0s_i = \mathtt 0 or 1\mathtt 1).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n,k≤1001 \le n, k \le 100)。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss(其中 si=0s_i = \mathtt 0 或 1\mathtt 1)。

输出格式

For each test case, output a single integer — the maximum number of classes you can sleep through today.

对于每个测试用例,输出一个整数——今天最多可以睡过的课程数量。

输入输出样例

  • 输入#1

    4
    4 1
    1001
    3 3
    000
    3 1
    001
    8 2
    01000101

    输出#1

    1
    3
    2
    2

说明/提示

In the first test case, you must listen to class 11 and class 44. After listening to class 11, you cannot fall asleep in class 22. So the only class you can sleep through is class 33.

In the second test case, you can sleep through all the classes.

In the fourth test case, you can only sleep through classes 11 and 55.

在第一个测试用例中,你必须听第 11 节课和第 44 节课。听完第 11 节课后,你不能在第 22 节课上睡觉。因此,唯一可以睡觉的课程是第 33 节课。

在第二个测试用例中,你可以睡过所有课程。

在第四个测试用例中,你只能睡过第 11 节课和第 55 节课。

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

首页