Educational Codeforces Round 39 (Rated for Div. 2) D. Timetable(动态规划)

STM32 SAI接口实战:用CubeMX快速配置多通道音频采集(附DMA优化技巧) 本文详细介绍了如何使用STM32的SAI接口通过CubeMX快速配置多通道音频采集系统,并提供了DMA双缓冲优化技巧。内容涵盖TDM模式配置、时钟同步、DMA优化及常见问题排查,帮助开发者高效实现高速数据采集应用。 阅读详情

D. Timetable
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

题解:bet[i][j]表示第i天旷j节课可以在家呆多长时间,这个可以暴力求出.
然后dp[i][j]表示前i天旷j节课可以在家呆多长时间,三重循环就得出正确结果了

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
const int N=510;
char a[N][N];
int  sum[N][N];
int  bet[N][N], dp[N][N];
int main()
{
    int i, j, k, n, m, V, temp, ans;
    cin>>n>>m>>V;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='1')
                sum[i][j] = sum[i][j-1]+1;
            else
                sum[i][j] = sum[i][j-1];
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            for(k=j-1;k<=m;k++)//考虑一节课也不上
            {
                temp = sum[i][m]-(sum[i][k]-sum[i][j-1]);
                bet[i][temp] = max(bet[i][temp], m-(k-j+1));
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=V;j++)
        {
            for(k=0;k<=j;k++)
                dp[i][j] = max(dp[i][j], dp[i-1][k]+bet[i][j-k]);
                //前i-1天旷k节加上这一天旷j-k节
        }
    }
    cout<<n*m-dp[n][V]<<endl;
    return 0;
}
Python多版本共存指南:用CMD命令一键切换3.6和3.8解释器(含pip使用技巧) 本文详细介绍了在Windows CMD环境下实现Python多版本(如3.6和3.8)共存与一键切换的完整方案。通过文件重命名策略、环境变量优化和自定义脚本,开发者可快速切换Python解释器版本,并管理各版本独立的pip依赖库,确保项目环境隔离与兼容性。 阅读详情

相关推荐

单点DToF激光测距传感器各家产品的比较

汇总DToF 单点测距传感器的相关信息

Linux 设备驱动概述及开发环境构建 (一) 1781

cf Educational Codeforces Round 39 D. Timetable

原题: D. Timetable time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Ivan is a student at Berland State University (BSU). There are n days i...

@fei 377

【74HC595芯片】核心驱动代码

74HC595是一个8位串行输入、并行输出的位移缓存器:并行输出为三态输出。在SCK 的上升沿,串行数据由SDL输入到内部的8位位移缓存器,并由Q7’输出,而并行输出则是在LCK的上升沿将在8位位移缓存器的数据存入到8位并行输出缓存器。当串行数据输入端OE的控制信号为低使能时,并行输出端的输出值等于并行输出缓存器所存储的值。

weixin_67147824的博客 1855

Educational Codeforces Round 39 (Rated for Div. 2) BC

题目链接 B题 解题思路: 给予a , b 然后执行以下操作: 这个需要注意的是数据范围以及如何处理超时。代码中给出注释。 代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> using namespace std; ...

LiangNiuMu的博客 208

Android Qcom USB Driver学习(五)

在前面的第二期中,我们知道一些非标的USB的充电类型Floatingcharger,其具有和普通DCP相似的大电流能力,但在最初检测的时候会限制Inputcurrentlimit到100mA,来进行检测是否是SDP类型,所以要支持大电流输入就需要进行vote操作,前面的几篇都有涉及,所以本文学习一下pmicusbcharger都相关的vote机制。...

Android驱动开发 2913

【Godot】构建可维护的游戏工程 —— 项目代码组织结构

本文系统梳理了Godot引擎项目组织原则与架构模式,提出场景中心化、命名规范一致性和资源隔离三大核心原则。推荐按功能模块划分目录结构(如scenes/、entities/、systems/),采用snake_case命名避免跨平台问题,并通过.gdignore优化资源管理。文章详细解析了自包含场景设计、信号驱动解耦等架构技巧,以及团队协作中的版本控制策略,强调通过模块化设计平衡一致性与实用性。最终目标构建清晰可维护的项目结构,使资源定位和功能扩展更加高效。(148字)

qq_40205510的博客 1185

构造分组背包(CF)

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

weixin_33840661的博客 156

OPPO 后端校招面试,过于简单了!

你好,我是 Guide。2026 届秋招陆续开奖公司的越来越多了,今天来看一家手机厂 OPPO。前几天,已经分享了和今年校招开奖的情况。其中,小红书的薪资最为炸裂,大白菜一年都能给到 51w+。不过,相对应的工作强度和压力也是真的难顶,确实很难有钱多又轻松的活!OV (OPPO 和 Vivo)这几年发展真还可以的,这两家的高端机口碑都不错。本人也是最近入手了一款 Vivo 的上一代旗舰,拍照是真的不错啊!每个月会有 1.2k 生活补贴,生活费是按照 8 % 缴纳。

JavaGuide 756

Educational Codeforces Round 39: D. Timetable(DP)

D. Timetabletime limit per test 2 secondsmemory limit per test 256 megabytesinput standard inputoutput standard outputIvan is a student at Berland State University (BSU). There are n days in Berland w...

加载中... 850

光学测量仿真软件:OpticsBuilder_(9).热应力分析与补偿

在OpticsBuilder中,定义材料的热膨胀系数可以通过API进行。以下是一个Python代码示例,展示如何在OpticsBuilder中定义材料的热膨胀系数。

kkchenjj的博客 1090

RT-DETR改进策略【小目标改进】| Shape-NWD:融合改进,结合Shape-IoU和NWD 更好地适应小目标特性

Bw−wgt2h−hgt2weight2Bweight2w−wgt​2h−hgt​2​其中weight2weight = 2weight2。

Limiiiing的博客 1554

Codeforces 946D - Timetable 【动态规划】

Codeforces 946D - Timetable 【动态规划】 Educational Codeforces Round 39 (Rated for Div. 2) Ivan is astudent at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classesat the university. There are m wo

Dust_heart的博客 695

Python中的join函数的用法

从语法、实例、应用三方面详尽地介绍join函数

阿黎逸阳的博客 2万+

Transformer架构深度解析:从自注意力到多头机制

在深度学习中,序列建模一直面临并行化与长距离依赖的双重挑战。注意力机制的引入打破了传统循环网络的时序瓶颈,催生了以Transformer为代表的新一代架构。通过自注意力计算,模型能够直接建立任意位置间的联系,实现全局信息交互;多头注意力机制则进一步赋予模型多角度语义特征捕捉能力,配合位置编码、残差连接与层归一化,使深层网络稳定高效地训练。这一设计在机器翻译、文本生成、图像识别等多模态任务中展现出极强的通用性,成为大语言模型与多模态智能系统的核心基石。理解其几何形状变化、掩码细节与训练优化策略,是掌握预训练模

weixin_30861459的博客 411

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Educational Codeforces Round 39 (Rated for Div. 2) D. Timetable (背包)

题意:    一个周期有n天,每天有m节课,一个周期的时间可以逃课k次。问至少要在学校里待多久。(从早上去的第一节课到最后一节课,如果没有课就不去)分析:    每天有x节课,我们需要考虑旷课[0,x]天内的所有的情况的的最小值用g【i】记录。g【i】旷课i节课这天最少上多久第u天的的最短时间是d【u】【k】 (k是旷课的次数)d【u】【k】=min(d【u-1】【i】+g【j】)(i+j == ...

努力打工 204

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

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

题目链接:https://codeforces.com/problemset/problem/946/D 题目大意:有n周,每周有m个小时。每节课1个小时。1代表有课。0代表没有课。现在可以逃k节课。每一天他都会从第一节课开始。到最后一课结束。问他现在可以逃k次课。让他在学校的时间最少。最小值为多少? 思路:对于第i周。我们可以用v[i][j]表示:第i周逃j节课在学校的最小时间。因为要结果最小...

H_ang的博客 201

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Educational Codeforces Round 39 (Rated for Div. 2)D. Timetable(dp)

先对每一行进行处理,每一行中g[i][j]代表第i行除去j节课最少上的课数。 知道了g[i][j],进行记忆化搜索,dp[i][j]代表第i行剩下k节课可以逃,最少上的课数。 两个地方需要dp,水平不够啊啊啊啊啊。O(∩_∩)O哈哈~ #include #define pb push_back #define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDe

但求心安的博客 286

Educational Codeforces Round 39 (Rated for Div. 2) D dp E 贪心

最近学了一下markdown,挺好玩的,以后博客就用 markdown 编辑了 +*+ Educational Codeforces Round 39 (Rated for Div. 2) D. Timetable 题意:有 n天, m 节课,最多逃 k 节课。每天这个人会从第一节课待到最后一节课,问最少在学校待多久。 tags: dp[i][j] 前 i 天逃了 j 节课最少待多久。 dp[i]...

weixin_30617561的博客 109

Educational Codeforces Round 39 (Rated for Div. 2) D Timetable

题目链接:点击打开链接题意:某大学一周有n天,一天有m小时工作/上课时间。给定n行m列0 和 1组成的字符,当第i行第j列为1时表示第i天第j小时有课。主角每天在学校的时间为第一节课到最后一节课之间(包括这两节课)的所有时间。现在主角想翘课,但一周最多翘k节课,那么现在主角就可以在翘课数小于等于k时选择自己想上的第一节课和最后一节课,主角当天在学校的时间则为这两节课之间(包括这两节课)的所有时间。...

LFhase‘s Blog 458

D. Timetable Educational Codeforces Round 39 (Rated for Div. 2)

题目链接:http://codeforces.com/contest/946/problem/D 题意:设一个星期有n天,每天有m小时,给你n个长为m的字符串(由0、1组成),1表示要上课的时段。你每天需要花在学校的时间是从第一个1到最后一个1(包括头尾)。你可以翘掉最多k节课,求你一个n天总计待在学校的最小时间 算法:dp 思路: 遍历每天 用mn[i]记录当天,要上连续的i节课后所需花费的...

凝望的博客 275

Educational Codeforces Round 39 (Rated for Div. 2) D - Timetable背包

由于我复制粘贴会自动换行,也不知道怎么办,就直接放链接了。 题目链接:http://codeforces.com/contest/1039/problem/A 这道题我真的是看了好久,一直不知道为什么,好像也找不到题解,只有自己慢慢想了。 首先它第i个输入是不能小于i的,因为如果是都在最短时间到达,那么他就是第i个,所以小于i非法...

天翼之城的博客 206

#分组背包 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 memory limit per test 256 megabytes input standard input output standard output I...

weixin_30779691的博客 117

Educational Codeforces Round 39 (Rated for Div. 2)

这场终于打了 B题一个地方忘开longlong,找了半天 C题没看公告被Hack D题分析后发现是背包dp,但没写出来,菜啊 A、B、C 签到 D. Timetable 分组背包 题意 给n天,每天有m节课,0代表这节课没有,1代表有,每天都必须从第一节课来,上完最后一节课才能走,现可以逃k节课,问最少待在学校的时间 分析 不难看出,逃的课一定是从某一天的开始或者结束...

weixin_30481087的博客 80

D. Timetable(分组背背背包)

这个题还蛮有意思的嘛......这个题还蛮有意思的嘛......这个题还蛮有意思的嘛...... 首先暴力求出第i天旷课j次能少掉的最大时间首先暴力求出第i天旷课j次能少掉的最大时间首先暴力求出第i天旷课j次能少掉的最大时间 于是分成i组,每组选一种漏课方式,背包容量是k,这就是一个分组背包于是分成i组,每组选一种漏课方式,背包容量是k,这就是一个分组背包于是分成i组,每组选一种漏课方式,背包容量是k,这就是一个分组背包 #include <bits/stdc++.h> using namesp

jziwjxjd的博客 566

codeforces Educational Codeforces Round 39 (Rated for Div. 2) D

D. Timetable time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ivan is a student at Berland State University (BS...

dianxue5904的博客 203
上一篇: Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array(找规律)
下一篇: Codeforces Round #470 (rated, Div. 2 C. Producing Snow(思维)
ffgcc
博客等级 码龄9年 32粉丝 296原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值