CF2154A.Notelock

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Teto is playing the hit rhythm game osu!. The game can be described by a binary string∗^{\text{∗}} ss of length nn and a positive integer kk where the following will happen in order:

  • You will choose some positions in ss to protect.
  • Then for each ii (1≤i≤n1 \le i \le n) in increasing order, Teto can set sis_i to 0\mathtt{0} if all the following are true:
    • si=1s_i = \mathtt{1},
    • sis_i is not protected,
    • the previous k−1k - 1 elements do not contain 1\mathtt{1}. More formally, 1\mathtt{1} does not occur in smax⁡(1,i−k+1),…,si−1s_{\max(1, i - k + 1)},\ldots,s_{i - 1}.

You dislike Teto (for some reason). So determine the minimum number of positions you need to protect to force her to leave ss unchanged.

∗^{\text{∗}}A binary string is a string that only consists of characters 0\mathtt{0} and 1\mathtt{1}.

Teto 正在玩热门节奏游戏 osu!。该游戏可用一个长度为 nn 的二进制字符串∗^{\text{∗}} ss 和一个正整数 kk 来描述,其规则如下(按顺序执行):

  • 你需选择 ss 中的若干位置进行保护;
  • 接着,对每个 ii(1≤i≤n1 \le i \le n),按 ii 递增的顺序,若满足以下全部条件,则 Teto 可将 sis_i 设为 0\mathtt{0}:
    • si=1s_i = \mathtt{1},
    • sis_i 未被保护,
    • 前 k−1k - 1 个元素中不包含 1\mathtt{1}。更严格地,1\mathtt{1} 不出现在子串 smax⁡(1,i−k+1),…,si−1s_{\max(1, i - k + 1)},\ldots,s_{i - 1} 中。

你不喜欢 Teto(出于某种原因)。因此,请确定你需要保护的最少位置数,使得 Teto 无法对 ss 做任何修改(即强制 ss 保持不变)。

∗^{\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≤1001 \le t \le 100). The description of the test cases follows.

The first line of each testcase contains integers nn and kk (2≤n≤10002 \le n \le 1000; 2≤k≤n2 \le k \le n) — the length of ss and kk.

The second line of each test case contains a binary string ss of length nn consisting of characters 0\mathtt{0} and 1\mathtt{1}.

The sum of nn across all testcases does not exceed 10001000.

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

每个测试用例的第一行包含两个整数 nn 和 kk(2≤n≤10002 \le n \le 1000;2≤k≤n2 \le k \le n)—— 分别表示字符串 ss 的长度和参数 kk。

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss,由字符 0\mathtt{0} 和 1\mathtt{1} 组成。

所有测试用例中 nn 的总和不超过 10001000。

输出格式

For each testcase, output the minimum number of positions you need to protect to force Teto to leave the string unchanged.

对于每个测试用例,输出你需要保护的最少位置数,以迫使 Teto 保持字符串不变。

输入输出样例

  • 输入#1

    9
    2 2
    11
    6 6
    100001
    5 3
    10000
    7 2
    1010101
    7 4
    0000001
    3 3
    010
    3 2
    011
    7 4
    1001001
    8 3
    00000000

    输出#1

    1
    1
    1
    4
    1
    1
    1
    1
    0

说明/提示

For the first testcase, you can protect the first element and have: s=11s = \mathtt{\color{red}{1}1}. Now Teto cannot change s1s_1 because it is protected and cannot change s2s_2 because s1=1s_1 = \mathtt{1}. It can be proven this is optimal.

For the second testcase, you can protect only the first element and have s=100001s = \color{red}{\mathtt{1}}\mathtt{00001}. Teto cannot change s1s_1 because it is protected and she cannot change s6s_6 because there is 1\mathtt{1} in the previous k−1k - 1 elements (100001\color{blue}{\mathtt{10000}}\mathtt{1}).

For the fourth testcase, you must protect s1,s3,s5,s7s_1,s_3,s_5,s_7 and have s=1010101s = \mathtt{\color{red}{1}0\color{red}{1}0\color{red}{1}0\color{red}{1}}. It can be shown that this is optimal. For example, if you did not protect s3s_3, then Teto can change it to 0\mathtt{0} (1010101\mathtt{\color{red}{1}\color{blue}{0}10\color{red}{1}0\color{red}{1}})

对于第一个测试用例,你可以保护第一个元素,得到:s=11s = \mathtt{\color{red}{1}1}。此时 Teto 无法修改 s1s_1(因其已被保护),也无法修改 s2s_2(因为 s1=1s_1 = \mathtt{1})。可以证明该方案是最优的。

对于第二个测试用例,你只需保护第一个元素,得到 s=100001s = \color{red}{\mathtt{1}}\mathtt{00001}。Teto 无法修改 s1s_1(因其已被保护),也无法修改 s6s_6(因为在前 k−1k - 1 个元素中存在 1\mathtt{1}(100001\color{blue}{\mathtt{10000}}\mathtt{1}))。

对于第四个测试用例,你必须保护 s1,s3,s5,s7s_1,s_3,s_5,s_7,从而得到 s=1010101s = \mathtt{\color{red}{1}0\color{red}{1}0\color{red}{1}0\color{red}{1}}。可以证明该方案是最优的。例如,若你不保护 s3s_3,则 Teto 可将其改为 0\mathtt{0}(1010101\mathtt{\color{red}{1}\color{blue}{0}10\color{red}{1}0\color{red}{1}})。

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

首页