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∗ s of length n and a positive integer k where the following will happen in order:
- You will choose some positions in s to protect.
- Then for each i (1≤i≤n) in increasing order, Teto can set si to 0 if all the following are true:
- si=1,
- si is not protected,
- the previous k−1 elements do not contain 1. More formally, 1 does not occur in smax(1,i−k+1),…,si−1.
You dislike Teto (for some reason). So determine the minimum number of positions you need to protect to force her to leave s unchanged.
∗A binary string is a string that only consists of characters 0 and 1.
Teto 正在玩热门节奏游戏 osu!。该游戏可用一个长度为 n 的二进制字符串∗ s 和一个正整数 k 来描述,其规则如下(按顺序执行):
- 你需选择 s 中的若干位置进行保护;
- 接着,对每个 i(1≤i≤n),按 i 递增的顺序,若满足以下全部条件,则 Teto 可将 si 设为 0:
- si=1,
- si 未被保护,
- 前 k−1 个元素中不包含 1。更严格地,1 不出现在子串 smax(1,i−k+1),…,si−1 中。
你不喜欢 Teto(出于某种原因)。因此,请确定你需要保护的最少位置数,使得 Teto 无法对 s 做任何修改(即强制 s 保持不变)。
∗二进制字符串是指仅由字符 0 和 1 组成的字符串。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). The description of the test cases follows.
The first line of each testcase contains integers n and k (2≤n≤1000; 2≤k≤n) — the length of s and k.
The second line of each test case contains a binary string s of length n consisting of characters 0 and 1.
The sum of n across all testcases does not exceed 1000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(2≤n≤1000;2≤k≤n)—— 分别表示字符串 s 的长度和参数 k。
每个测试用例的第二行包含一个长度为 n 的二进制字符串 s,由字符 0 和 1 组成。
所有测试用例中 n 的总和不超过 1000。
输出格式
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=11. Now Teto cannot change s1 because it is protected and cannot change s2 because s1=1. It can be proven this is optimal.
For the second testcase, you can protect only the first element and have s=100001. Teto cannot change s1 because it is protected and she cannot change s6 because there is 1 in the previous k−1 elements (100001).
For the fourth testcase, you must protect s1,s3,s5,s7 and have s=1010101. It can be shown that this is optimal. For example, if you did not protect s3, then Teto can change it to 0 (1010101)
对于第一个测试用例,你可以保护第一个元素,得到:s=11。此时 Teto 无法修改 s1(因其已被保护),也无法修改 s2(因为 s1=1)。可以证明该方案是最优的。
对于第二个测试用例,你只需保护第一个元素,得到 s=100001。Teto 无法修改 s1(因其已被保护),也无法修改 s6(因为在前 k−1 个元素中存在 1(100001))。
对于第四个测试用例,你必须保护 s1,s3,s5,s7,从而得到 s=1010101。可以证明该方案是最优的。例如,若你不保护 s3,则 Teto 可将其改为 0(1010101)。
输入解题思路,AI测评打分。不知道怎么写?