来源: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. gnome extensions 推荐 (fedora 28 常用gnome 插件备份)

    当我们进行重新安装系统(fedora 28)的时候,需要初始安装一些 gnome 插件,来进行完善我们的使用. 首先我们应该进行安装 gnome-tweak 工具来进行定制化系统. tweak 可以进 ...

  2. emWin及StemWin使用中关于菜单栏的应用与问题

    前言:在我看来,emWin和StemWin就是基本相同的库文件,关于这个库文件的移植,网络上有很多教材,比如“ALIENTEK emWin开发手册”,他们家提供了各种STM32系列的开发手册,我这里记 ...

  3. January 10th, 2018 Week 02nd Wednesday

    No need to have a reason to love you. Anything can be a reason not to love you. 喜欢你,不需要什么理由:不喜欢你,什么都 ...

  4. Beta冲刺博客集合贴

    Beta阶段第一次冲刺 Beta阶段第二次冲刺 Beta阶段第三次冲刺 Beta阶段第四次冲刺 Beta阶段第五次冲刺 Beta阶段总结博客

  5. python windows环境下文档备份

    #python 2.7 #Filename:backup.py import os import time source = [r'C:\Users\zeng.shufang\Desktop\mess ...

  6. Windows安装PostgreSQL11.1

    Windows安装PostgreSQL11.1 安装过程如下: 1.下载安装包postgresql-11.1-1-windows-x64.exe 2.点击下一步 3.选择安装位置,默认路径C:\Pro ...

  7. Pycharm 安装 idea VIM

    直接在线安装 1.File->Settings->Plugins->Install JetBrains Plugins 2.点击install安装ideavim 3.也许需要的切换v ...

  8. mysql数据库的test类型

    文章参考自 window系统参考:http://blog.sina.com.cn/s/blog_46f7bb6d0102vde3.html linux 参考:http://www.linuxeye.c ...

  9. UI自动化测试模型

    所谓的自动化测试模型,可以理解为自动化测试框架+工具设计的一种思想产物. 先说说库.框架.工具之间的区别: 库:英文名Library,由代码集成的一个产品,供用户调用.面向对象的库叫做类库,面向过程的 ...

  10. linux 修改内核参数 如何生效?

    Linux 操作系统修改内核参数有3种方式: 修改 /etc/sysctl.conf 文件,加入配置选项,格式为 key = value ,修改保存后调用 sysctl -p 加载新配置使用 sysc ...