You work as a system administrator in a dormitory, which has ?n rooms one after another along a straight hallway. Rooms are numbered from 11 to ?n.
You have to connect all ?n rooms to the Internet.
You can connect each room to the Internet directly, the cost of such connection for the ?i-th room is ?i coins.
Some rooms also have a spot for a router. The cost of placing a router in the ?i-th room is also ?i coins. You cannot place a router in a room which does not have a spot for it. When you place a router in the room ?i, you connect all rooms with the numbers from ???(1, ?−?)max(1, i−k) to ???(?, ?+?)min(n, i+k) inclusive to the Internet, where ?k is the range of router. The value of ?k is the same for all routers.
Calculate the minimum total cost of connecting all ?n rooms to the Internet. You can assume that the number of rooms which have a spot for a router is not greater than the number of routers you have.
Input
The first line of the input contains two integers ?n and ?k (1≤?,?≤2⋅1051≤n,k≤2⋅105) — the number of rooms and the range of each router.
The second line of the input contains one string ?s of length ?n, consisting only of zeros and ones. If the ?i-th character of the string equals to '1' then there is a spot for a router in the ?i-th room. If the ?i-th character of the string equals to '0' then you cannot place a router in the ?i-th room.
Output
Print one integer — the minimum total cost of connecting all ?n rooms to the Internet.
确实,比赛的时候没想到嘤嘤嘤!这都不重要!!!关键是…… 哼!
首先,我们要想,对于每个点,有的点是可以用“1”的(也就是放个路由器),有的点是可以直接使用i价值链接上网,或者收益于其他的路由器的。
那么,我们首先考虑没有放置路由器空间的点,它是不是可以看成前面有路由器的点的受益者,或者是直接有前一个点的价值加上i来满足条件。
其次,看可以放置路由器的点,它的价值应该如何去确定呢?可以找到前面的[i - K, i - 1]区间的为不使用路由器的最小值,然后再比较[i - K -1, i - 1]区间内的使用路由器的最小值,不断的这样递推下去即可。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include