http://codeforces.com/problemset/problem/946/D

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 nmk 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?

Input

The first line contains three integers nm 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).

Output

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

Examples
input

Copy
2 5 1
01001
10110
output
5
input

Copy
2 5 0
01001
10110
output
8
Note

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.

// 去吧!皮卡丘! 把AC带回来!
// へ     /|
//   /\7    ∠_/
//   / │   / /
//  │ Z _,< /   /`ヽ
//  │     ヽ   /  〉
//  Y     `  /  /
//  イ● 、 ●  ⊂⊃〈  /
//  ()  へ    | \〈
//   >ー 、_  ィ  │ //
//   / へ   / ノ<| \\
//   ヽ_ノ  (_/  │//
//    7       |/
//    >―r ̄ ̄`ー―_
//**************************************
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <class T> inline T min(T a, T b, T c, T d) {
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d) {
return max(max(a, b), max(c, d));
}
#define pi acos(-1)
#define mem(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int maxn = 3e5 + ;
// name*******************************
int n, m;
int a[][];
int K;
int kk[][];//kk[i][j]记录第i行删掉j个的最小代价,为后面dp服务
int dp[][];//dp[i][j]:前i行,共删掉j个所获最下代价
int cnt[];//记录每组的1的个数
int sum=; //sum这里记录下1的总个数,若K大于sum,直接输出0
// function****************************** //***************************************
int main() {
// ios::sync_with_stdio(0); cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
cin >> n >> m >> K;
me(dp, );
me(kk, );
For(i, , n) {
For(j, , m) {
int x;
scanf("%1d", &x);//限宽输入
if (x) {
a[i][++cnt[i]] = j;
}
}
//选定j,k为起始终止点
For(j, , cnt[i]) {
For(k, j, cnt[i]) {
kk[i][(j - ) + cnt[i] - k] =
min(kk[i][(j - ) + cnt[i] - k], a[i][k] - a[i][j] + );
}
}
kk[i][cnt[i]] = ;
sum+=cnt[i];
}
if(K>=sum){
cout<<;
return ;
}
For(i, , min(K, cnt[])) {
dp[][i] = kk[][i];
}
For(i, , n) {
For(j, , K) {
For(k, , min(j,cnt[i])) {
dp[i][j] = min(dp[i][j], dp[i - ][j - k] + kk[i][k]);
}
}
}
cout << dp[n][K]; return ;
}

D. Timetable的更多相关文章

  1. #分组背包 Educational Codeforces Round 39 (Rated for Div. 2) D. Timetable

    2018-03-11 http://codeforces.com/contest/946/problem/D D. Timetable time limit per test 2 seconds me ...

  2. Codeforces 946D - Timetable (预处理+分组背包)

    题目链接:Timetable 题意:Ivan是一个学生,在一个Berland周内要上n天课,每天最多会有m节,他能逃课的最大数量是k.求他在学校的时间最小是多少? 题解:先把每天逃课x节在学校呆的最小 ...

  3. Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)

    A. BowWow and the Timetable time limit per test1 second memory limit per test256 megabytes inputstan ...

  4. Distributed Databases and Data Mining: Class timetable

    Course textbooks Text 1: M. T. Oszu and P. Valduriez, Principles of Distributed Database Systems, 2n ...

  5. [Codeforces 946D]Timetable

    Description 题库链接 给你一个 \(N\times M\) 的 \(01\) 矩阵,你可以从中将一些 \(1\) 变为 \(0\) ,最多 \(K\) 次.使操作之后使得每行最远的 \(1 ...

  6. Codeforces 37D Lesson Timetable - 组合数学 - 动态规划

    题目传送门 神奇的门I 神奇的门II 题目大意 有$n$组学生要上课2次课,有$m$个教室,编号为$1$到$m$.要确定有多少种不同的安排上课的教室的方案(每组学生都是本质不同的),使得它们满足: 每 ...

  7. 2018.12.08 codeforces 946D. Timetable(背包)

    传送门 题意简述:有一个人上n天课,每天有m个小时的时间安排表(一个01串),为1表示要上课,否则不上课,求出如果可以最多翘kkk节课这nnn天在校待的总时间的最小值(一天必须在所有课上完后才能离开) ...

  8. CodeForces 946D Timetable (DP)

    题意:给定 n,m,K,表示某个人一个周有 n 天,每天有 m 节课,但是他可以跳过 K 节课,然后下面每行一个长度为 m 个01字符串,0 表示该人在这一小时没有课,1 表示该人在这一个小时有课,每 ...

  9. CodeForces - 946D Timetable (分组背包+思维)

    题意 n天的课程,每天有m个时间单位.若时间i和j都有课,那么要在学校待\(j-i+1\)个时间.现在最多能翘k节课,问最少能在学校待多少时间. 分析 将一天的内容视作一个背包的组,可以预处理出该天内 ...

随机推荐

  1. 活字格企业 Web 应用生成器新手上路指南

    活字格是一款企业 Web 应用生成器,使用了类 Excel 的设计界面,通过简单的拖拽操作,就能快速制作出一个 Web 信息管理系统.在整个使用过程中无需专业软件知识,没有任何技术门槛,能轻松实现各行 ...

  2. Android的onCreateOptionsMenu()创建菜单Menu

    android一共有三种形式的菜单:             1.选项菜单(optinosMenu)             2.上下文菜单(ContextMenu)             3.子菜 ...

  3. Dlink DIR-823G 漏洞挖掘过程

    前言 本文由 本人 首发于 先知安全技术社区: https://xz.aliyun.com/u/5274 初步分析 首先下载固件 https://gitee.com/hac425/blog_data/ ...

  4. DBFlow(4.2)新版使用

    DBFlow新版使用 一.DBFlow4.2.4介绍 DBFlow是一个基于AnnotationProcessing(注解处理器)的ORM框架.此框架设计为了速度.性能和可用性.消除了大量死板的数据库 ...

  5. 抓取远程master分支到本地,并与UI分支合并

    1.pull (1)UI:  git add . git commit -m   git checkout master (2)master:  git pull origin master  git ...

  6. 如何忽略.gitignore文件的提交

    1.默认的.gitignore文件无法忽略,如果想要忽略可以把.gitignore里面的文件转移到项目下面的 .git/info/exclude 里面, 2..gitignore可以直接使用插件,参照 ...

  7. 探索ORM之iBati(一)

    ibatis   iBATIS一词来源于“internet”和“abatis”的组合,是一个由Clinton Begin在2001年发起的开放源代码项目.最初侧重于密码软件的开发,现在是一个基于Jav ...

  8. zTree自定义节点name显示样式

    //setting中配置属性 view: { showLine:false, dblClickExpand: true, showIcon: false, addDiyDom: addDiyDom / ...

  9. Oracle EBS AP银行显示不全

  10. 如何在 OS X 中安装 ruby

    如何在 OS X 中安装 ruby 软件包下载 链接: http://pan.baidu.com/s/1mgMil5I 密码: tiqg 安装 http://brew.sh/ 1. 先安装 brew( ...