CF946D.Timetable

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.

There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.

Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.

Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?

伊万是贝尔兰国立大学(BSU)的一名学生。贝尔兰一周有 nn 天,每一天伊万可能在大学上若干节课。

贝尔兰每天有 mm 个课时,且大学的每节课恰好持续一小时。若某天伊万的第一节课在第 ii 个课时,最后一节课在第 jj 个课时,则他在该天于大学内停留 j−i+1j - i + 1 小时。若某天伊万没有任何课程,则他待在家中,当天在大学内停留时间为 00 小时。

伊万不喜欢在大学里花费过多时间,因此他决定跳过一些课程。他在整周内最多只能跳过 kk 节课。在确定了哪些课跳过、哪些课参加之后,伊万每天将恰好在他未跳过的第一节课程开始前进入大学,并在他决定参加的最后一节课程结束后离开大学。若某天伊万跳过了全部课程,则他当天完全不去大学。

已知 nn、mm、kk 以及伊万的课程表,请你计算:在最多跳过 kk 节课的前提下,伊万一周内在大学中所需停留的最少总小时数是多少?

输入格式

The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.

Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).

第一行包含三个整数 nn、mm 和 kk(1≤n,m≤5001 \leq n, m \leq 500,0≤k≤5000 \leq k \leq 500),分别表示 Berland 一周的天数、每天的工作小时数,以及 Ivan 可以跳过的课程数量。

接下来是 nn 行,第 ii 行包含一个长度为 mm 的二进制字符串。若第 ii 行中第 jj 个字符为 1,则表示 Ivan 在第 ii 天的第 jj 小时有一节课(若为 0,则该时段无课)。

输出格式

Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.

如果伊万一周内最多跳过 k 节课,那么他本周在大学中至少需要花费多少小时?

输入输出样例

  • 输入#1

    2 5 1
    01001
    10110

    输出#1

    5
  • 输入#2

    2 5 0
    01001
    10110

    输出#2

    8

说明/提示

In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.

In the second example Ivan can't skip any lessons, so he spends 4 hours every day.

在第一个例子中,伊万可以在第一天跳过任意一节课,因此他在第一天花费 1 小时,在第二天花费 4 小时。

在第二个例子中,伊万无法跳过任何课程,因此他每天都要花费 4 小时。

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

首页