来源: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. 修改css的(屏蔽)overflow: hidden;实现浏览器能把网页全图保存成图片

    摘要: 1.项目需要,需要对网页内容“下载”保存成全图片 2.QQ浏览器等主流浏览器都支持这种下载保存功能 3.项目需要场景:编写好的项目维护文档,放在服务器上.如果是txt不能带图片可视化,如果wo ...

  2. Debian-Linux配置网卡网络方法

    Debian不同于centos系统,网卡配置不是在/etc/sysconfig/network-scrip里面,而是在/etc/network/interfaces里面 1.Debian网络配置 配置 ...

  3. [笔记]一些STL用法

    参考资料:STL 在 OI 中的应用 离散化 std::unique 功能:对有序的容器重新排列,将第一次出现的元素从前往后排,其他重复出现的元素依次排在后面 返回值:返回迭代器,迭代器指向的是重复元 ...

  4. Java关于ReentrantLock获取锁和释放锁源码跟踪

    通过对ReentrantLock获取锁和释放锁源码跟踪主要想进一步深入学习AQS. 备注:AQS中的waitStatus状态码含义:

  5. github(1)安装及使用图文详解

    教程https://blog.csdn.net/qq_32166627/article/details/54427622 下载地址:https://desktop.github.com/

  6. 【转】Emgu 图像阈值

    原文地址:http://www.cnblogs.com/CoverCat/p/5043833.html 转载,备查 Visual Studio Community 2015 工程和代码:http:// ...

  7. Linux安装solr

    solr官网下载地址为:http://mirror.bit.edu.cn/apache/lucene/solr/ 以7.6.0版本作为实践 1.下载 wget http://mirror.bit.ed ...

  8. mysql innodb引擎 一次线上死锁分析排查步骤

    我们的线上erp系统一天使用人员反映部分数据死活保存不上而且页面操作很慢.开始以为操作数据量大的原因, 后来查看了我们线上的glowroot系统,发现slowtrace中有超长时间的访问,点开查看详情 ...

  9. Python脱产8期 Day01

    一 编程语言与目的 1.有特定语法,可以通过编程的方式,让计算机进行识别,从而让计算机根据人的意愿完成人想让其完成的事 2.控制奴役计算机,让其完成你想让它完成的事,从而解放人力. 二 计算机 五大组 ...

  10. java.lang.UnsatisfiedLinkError: No implementation found for int com.baidu.platform.comjni.map.commonmemcache.JNICommonMemCache.Create()

    完整异常: Process: com.example.ai.tabhostdemo, PID: 1287 java.lang.UnsatisfiedLinkError: No implementati ...