来源:codeforces                                              D. Timetable

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

思路:
想暴力,不过只是想想而已
总结:
dp好难,和以前遇到的dp一样,都是dp[i][j]代表前i行,状态为j时的最优值,状态的表示比较难,nm数组用来表示当剩下i个1时要花的时间,
枚举所有逃课节数,再枚举当前行的逃课数量
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
char tl[][];
int dp[][],p[],mn[],n,m,kk,c,l;
int main()
{
cin>>n>>m>>kk;
for(int i=;i<=n;i++)
scanf("%s",tl[i]);
for(int i=;i<=n;i++)
{
c=;
for(int j=;j<m;j++)
if(tl[i][j]=='')
p[++c]=j;
for(int j=;j<=c;j++)
{
mn[j]=;
for(int k=;k+j-<=c;k++)
mn[j]=min(mn[j],p[k+j-]-p[k]+);
}
for(int j=;j<=kk;j++)
for(l=min(c,j),dp[i][j]=INF;l>=;l--)
dp[i][j]=min(dp[i][j],dp[i-][j-l]+mn[c-l]);
}
cout<<dp[n][kk]<<endl;
return ;
}

cf946d 怎样逃最多的课dp的更多相关文章

  1. BZOJ.2660.[BJOI2012]最多的方案(DP)

    题目链接 首先我们知道: 也很好理解.如果相邻两项出现在斐波那契表示法中,那它们显然可以合并. 所以我们能得到\(n\)的斐波那契表示,记\(pos[i]\)为\(n\)的斐波那契表示法中,第\(i\ ...

  2. 大逃杀(树上dp)

    这道题和宝藏差不多吧,转移的时候比较麻烦的. 代码中分量很多种情况. h更新比较麻烦 这两幅图表示了双边更新中3,4连个h更新,下面比较好理解的吧. #include<cstring> # ...

  3. 动态规划之经典数学期望和概率DP

    起因:在一场训练赛上.有这么一题没做出来. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6829 题目大意:有三个人,他们分别有\(X,Y,Z\)块钱 ...

  4. dp杂题(根据个人进度选更)

    ----19.7.30 今天又开了一个新专题,dp杂题,我依旧按照之前一样,这一个专题更在一起,根据个人进度选更题目; dp就是动态规划,本人认为,动态规划的核心就是dp状态的设立以及dp转移方程的推 ...

  5. Timetable CodeForces - 946D (区间dp)

    大意: n天, 每天m小时, 给定课程表, 每天的上课时间为第一个1到最后一个1, 一共可以逃k次课, 求最少上课时间. 每天显然是独立的, 对每天区间dp出逃$x$次课的最大减少时间, 再对$n$天 ...

  6. poj-3616 Milking Time (区间dp)

    http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...

  7. Hackers' Crackdown( UVA UVA 11825状压dp)

    题意:N台电脑,现在有N种服务,现在你可以在每台电脑终止一项服务,他和他相邻的电脑都会被关闭,如果一项服务在所有电脑都没运行,该项服务成功被破坏,问最多能破坏几种服务. 分析:把n个集合分成尽量多组, ...

  8. POJ 2029 DP || 暴力

    在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP  水题 暴力: #include "stdio.h" #include "string.h" int ...

  9. dp之背包总结篇

    //新手DP学习中 = =!! 前言:背包问题在dp中可以说是经典,作为一个acmer,到现在才正式学习dp,可以说是比较失败的.我个人比较认同一点,想要做一个比较成功的acmer,dp.搜索.数学必 ...

随机推荐

  1. Linux系统将http转为https

    想把网站由http访问转变为https访问并没有想象中那么难,网上查了一些资料,想要转为https需要SSL安全证书,这里推荐一款景安网络的证书,可以免费试用一年时间,自己拿来实践还是很不错的选择. ...

  2. Codeforces Round #245 (Div. 2)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/yew1eb/article/details/25609981 A Points and Segmen ...

  3. centos7下安装docker(9.3容器对资源的使用限制-Block IO))

    Block IO:指的是磁盘的读写,docker 可以通过设置权重,限制bps和iops的方式控制容器读写磁盘的带宽 注:目前block IO限额只对direct IO(不使用文件缓存)有效. 1.B ...

  4. ansible-role写法

    一.role目录的创建: cd /etc/ansible/ mkdir -pv roles/{websrvs,dbsrvs}/{tasks,files,templates,meta,handlers, ...

  5. PHP开发小技巧①①—php实现手机号码显示部分

    从个人信息保护性的角度来讲,我们在开发过程中总会想办法去保护用户的一些个人信息.就如本篇博文所讲,我们有时会将用户的手机号码只显示出部分,这是很多网站都有做的功能.这个功能实现起来也是特别的简单,只需 ...

  6. 完美解决centos安装linux后不能上网的问题

    vi / etc /sysconfig/network-scripts/ifcfg-eth0 配置ip地址 DEVICE=eth0 HWADDR=00:0C:29:8C:F7:6F TYPE=Ethe ...

  7. RMAN 数据库克隆文件位置转换方法

    在使用RMAN克隆数据库时,如果辅助数据库(新数据库)使用了与目标数据库(原数据库)使用了不同的路径,那么就存在位置转换的问题.在Oracle中,控制文件用于定位数据文件以及联机重做日志文件,如果没有 ...

  8. Jmeter之tomcat性能测试+性能改进措施

    Jmeter用于tomcat性能测试,因为项目部署在tomcat,正常情况下,一个tomcat可以承受500个并发,通过修改配置,及其相关的tomcat优化,可以承受到1000个并发. 如何测试tom ...

  9. QT QListWidget 简单的操作

    以下是简单的 listWidget 的方法的功能 listWidget = QListWidget() #实例化一个(item base)的列表 listWidget.addItem('dd') #添 ...

  10. C#位运算实际运用

    前言 前几天写了一篇关于c#位操作,c#位运算基本概念与计算过程 最后提到一个实际问题 需求:C# 用两个short,一个int32拼成一个long型 要求:现在有两个short和一个int,需要拼成 ...