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?

Input

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).

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.

题意 : 输入数据有 n 行,代表天数,然后每天有 m 节课, 他可以选择性的翘 K 节课,问最终在校时间最短是多少。

思路分析 : 最开始想的是 3 层 for 的大暴力,每次逃的课一定是某一天的最左或最右的课,但是这样不一定对,可以想一想

后来看了大佬的博客,想明白了,是一个分组背包的问题,我们要做的就是提前预处理出在某一天我们逃 x 节课的所减少的在校时间,当一天的课全部逃后,那么所减少的在校时间就是 m ,然后 3层 for 搞定dp 就ok了

代码示例 :

int n, m, p;
char s[505];
int pos[505][505], num[505];
int c[505][505]; // 删除 k 个字符后的花费最多可以节约的花费
int dp[505]; int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> m >> p;
for(int i = 1; i <= n; i++){
scanf("%s", s+1);
int pp=1;
for(int j = 1; j <= m; j++){
if (s[j] == '1') {num[i]++, pos[i][pp++] = j;}
}
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= num[i]-1; j++){
int res = inf;
for(int k = 0; k <= num[i]-1; k++){
if (j-k < 0) break;
int q = j - k; // q右边开始选多少个1 k表示左边
res = min(res, pos[i][num[i]-q]-pos[i][k+1]+1);
}
c[i][j] = m-res;
}
c[i][num[i]] = m;
}
//for(int i = 1; i <= n; i++){
//for(int j = 0; j <= m; j++){
//cout << c[i][j] << " " ;
//}
//cout << endl;
//}
for(int i = 1; i <= n; i++){
for(int j = p; j >= 0; j--){
for(int k = 0; k <= min(num[i], j); k++){
dp[j] = max(dp[j], dp[j-k]+c[i][k]);
}
}
//printf("i = %d dp = %d\n",i, dp[p]);
}
cout << n*m-dp[p] << endl;
return 0;
}

最新文章

  1. css中vw,vh单位对于UC的兼容性问题
  2. Sublime Text 3常用快捷键
  3. nbtstat -a &lt;IP&gt; 会显示主机名、所在工作组等信息
  4. PHP获取当前url路径的函数及服务器变量
  5. skymvc网站测试之mysql数据生成
  6. Android bitmap图片处理
  7. HTTP -&gt; Asp.net (第一篇)
  8. 浅谈敏捷组织中PMO的角色
  9. libguestfs-tools 虚拟机磁盘管理工具
  10. 一步一步教你用c# entity framework6 连接 sqlite 实现增删改查
  11. Android-AnsyncTask异步任务
  12. 076、创建Rex-Ray volume (2019-04-23 周二)
  13. CODEFORCES ROUND #761 ANALYSES BY TEAM:RED &amp; BLACK
  14. Spring Boot之执行器端点(Actuator Endpoint)实现剖析
  15. Hexo + Github 个人博客设置以及优化
  16. WebLogic安装及部署
  17. 参数在一个线程中各个函数之间互相传递的问题(ThreadLocal)
  18. ElasticSearch 2 (32) - 信息聚合系列之范围限定
  19. vue 钩子
  20. jQuery .tmpl(), .template()学习资料小结

热门文章

  1. P1093 铺地毯
  2. 为什么阿里代码规约要求避免使用 Apache BeanUtils 进行属性复制
  3. VC++ CMsflexgrid 使用
  4. ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(12)之后台功能总结
  5. 1119 机器人走方格 V2 (组合数学)
  6. C# 程序集数量对软件启动性能的影响
  7. vue-learning:6-template-v-bind
  8. OpenCV与MFC实战之图像处理 样本采集小工具制作 c++MFC课程设计
  9. 看各类框架源码淘来的一些JavaScript技巧
  10. 第二阶段:4.商业需求文档MRD:6.PRD-其他需求