CodeForces - 812B

AURIX-TC3xx-GTM详解六-DPLL(Digital PLL Module)-寄存器1-DPLL寄存器 主要有下图这些寄存器2、 阅读详情

Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.

The building consists of n floors with stairs at the left and the right sides. Each floor has m rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with n rows and m + 2 columns, where the first and the last columns represent the stairs, and the m columns in the middle represent rooms.

Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights.

Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off.

Input
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively.

The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor.

The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0.

Output
Print a single integer — the minimum total time needed to turn off all the lights.

Example
Input
2 2
0010
0100
Output
5
Input
3 4
001000
000010
000010
Output
12
Input
4 3
01110
01110
01110
01110
Output
18
Note
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs.

In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor.

In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.

傻逼dp坑贼鸡儿多烦死了。。。。

测试点一个一个的过

wa2到wa7才过。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
int tu[330][330];
int dp[200][200];
string tt[123];
int main()
{
    int n, m;
    cin >> n >> m;
    for (int a = 1; a <= n; a++)tu[a][0] = 0,tu[a][1]=0x3f3f3f3f,tu[a][2]=0;
    for (int a = 1; a <= n; a++)cin >> tt[a];
    for (int a = n,c=1; a >= 1; a--,c++)
    {
        string q;
        q = tt[a];
        for (int b = 0; b < q.size(); b++)
        {
            if (q[b] == '0')continue;
            tu[c][0]++;
            tu[c][1] = min(tu[c][1], b+1);
            tu[c][2] = max(tu[c][2], b + 1);
        }
    }
    if (n == 1)
    {
        cout << tu[1][2]-1;
        return 0;
    }
    if (!tu[1][0])
    {
        dp[1][1] = 0;
        dp[1][2] = m + 1;
    }
    else
    {
        dp[1][1] = 2 * (tu[1][2] - 1);
        dp[1][2] = m + 1;
    }
    for (int a = 2; a < n; a++)
    {
        if (!tu[a][0])
        {
            dp[a][1] = dp[a - 1][1] + 1;
            dp[a][2] = dp[a - 1][2] + 1;
            dp[a][1] = min(dp[a][1], dp[a - 1][2] + m + 2);
            dp[a][2] = min(dp[a][2], dp[a - 1][1] + m + 2);
            continue;
        }
        dp[a][1] = dp[a - 1][1] + 1 + 2 * (tu[a][2] - 1);
        dp[a][1] = min(dp[a][1], dp[a - 1][2] + m + 2);
        dp[a][2] = dp[a - 1][2] + 1 + 2 * (m + 2 - tu[a][1]);
        dp[a][2] = min(dp[a][2], dp[a - 1][1] + m + 2);
    }
    int jg;
    for (int a = n;a>=0; a--)
    {
        if (!tu[a][0])continue;
        if (a == 1)
        {
            cout << tu[1][2] - 1;
            return 0;
        }
        cout << min(dp[a - 1][1] + tu[a][2], dp[a - 1][2] + m + 2 - tu[a][1] + 1);
        return 0;
    }
    cout << 0;
}
【域控制器EMC】域控制器EMC设计总结 汇总项目设计当中关于EMC的设计要点,主要从原理设计、Layout、结构、外设部分总结。满足要求的器件和合理的电路能降低电磁干扰;正确的布局、接地、信号路径、屏蔽等可以减少电磁辐射。结构件设计也会对EMC性能产生影响。 阅读详情

相关推荐

C#实现跨域访问共享文件夹的账号密码验证方案

本文详细介绍了在C#中实现跨域访问共享文件夹的账号密码验证方案。通过调用Windows API LogonUser函数,结合LOGON32_LOGON_NEW_CREDENTIALS登录类型,可安全模拟指定用户身份,有效解决工作组与域环境间的文件共享访问难题。文章提供了完整的工具类封装、多种实战场景示例及详细的错误排查指南。

pea55的博客 546

codefoces 812B——Sagheer, the Hausmeister(动态规划)

B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Some people leave the lights at

say_c_box的博客 766

思澈sdk-新建lcd

co5300至此有3个同ID的驱动,在co5300xxxx.c的LCD_DRIVER_EXPORT(co5300, LCD_ID, &lcdc_int_cfg, &CO5300_drv, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT, 2);2 在customer\peripherals\Kconfig_lcd中添加如下配置(注意修改的地方有两个LCD_USING_TFT_CO5300_143)5 在该文件中的config LCD_DPI配置项下添加:(这里300为DPI)

gongyuan073的专栏 1400

CodeForces 812B-Sagheer, the Hausmeister

CodeForces 812B-Sagheer, the Hausmeister 题目链接:B. Sagheer, the Hausmeister 思路: 题目大意是n层楼,每层楼有m个房间,该楼有两部楼梯,位于房间的两侧,从当前楼梯到相邻层楼梯口,当前房间到相邻房间或相邻楼梯口都需要一分钟,问起点位于底层左楼梯口,最少多长时间才能把灯全部关掉,不用回到起点。 从最底层...

[SZU_Crayon] 404

GEE:连续变化检测 CCD 第一步(导出ee.Algorithms.TemporalSegmentation.Ccdc函数的结果)

连续变化检测与分类(Continuous Change Detection and Classification, CCDC)主要有两个组件,一个连续变化检测 CCD,另外一个分类。在 Google Earth Engine (GEE)平台上进行 CCD 时间序列变化检测的时候,为了防止内存超限问题,将代码分为2阶段执行。第一阶段是运行 `ee.Algorithms.TemporalSegmentation.Ccdc` 函数,本文将详细介绍 CCD 的第一阶段的代码。

养乐多的博客 2508

YOLOv11+BiFPN双向特征金字塔:全方位解析多尺度检测性能优化指南

飞书链接:https://ecn6838atsup.feishu.cn/wiki/EhRtwBe1CiqlSEkHGUwc5AP9nQe?购买即可解锁800+YOLO优化文章,并且还有海量深度学习复现项目,价格仅需两杯奶茶的钱,每日更新。函数中添加BiFPN的解析逻辑(找到。链接可用,不要多复制空格了。密码:946m22&8。

FJN110的博客 311

codeforce刷题 1

1.Sequence Pair Weight 题目大意 给定一个长度为 n 的数组 a,规定 i < j 且 ai = aj 为一个数对,求数组 a 的 所有连续子序列中有多少个这样的数对,输出总数。 解题思路 易得如果一个一个子序列去遍历的话,那么大约有 n*n/2 个子序列,会超时所以要考虑更简单的方法,采用动态规划的思想,dp[i] 代表以第 i 个数为结尾的所有子序列的答案总数,同时用 map 储存每一个数字出现的次数 #include<iostream> #include<

jojo_it_journey的博客 746

使用epiDisplay包中的logistic

其中的logistic.display函数可以用于获取逻辑回归模型的汇总统计信息,包括自变量的优势比和置信区间,以及回归系数的Wald检验的p值。最后,我们使用print函数打印出汇总统计信息。使用epiDisplay包中的logistic.display函数获取逻辑回归模型的汇总统计信息(包括自变量的初始和调整后的优势比及置信区间,回归系数的Wald检验的p值)- R语言。通过使用logistic.display函数,我们可以方便地获取逻辑回归模型的重要统计信息,并对自变量的影响进行解释和推断。

CyberJolt的博客 617

812B(状态压缩)

B. Sagheer, the Hausmeister time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Some people leave the lights at their workplaces on when they l

creatorx的博客 591

计算机应用数学--第一次作业

中科大 计算机应用数学 第一次作业

一杯水果茶!足矣~ 1334

Doris实战——结合Flink构建极速易用的实时数仓

Doris实战——结合Flink构建极速易用的实时数仓

爱吃辣条的博客 8238

Codeforces 812B-Sagheer, the Hausmeister

Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Some people leave the lights at the

wang_128的博客 1146

点云处理实操(四) -PCL中的点云三角化

点云处理实操(四) -PCL中的点云三角化

cangqiongxiaoye的博客 943

Codeforces 812B-Sagheer, the Hausmeister (DFS暴力)

  B. Sagheer, the Hausmeister 题目链接:http://codeforces.com/problemset/problem/812/B​​​​​​​   time limit per test 1 second memory limit per test 256 megabytes input standard input output stand...

Harukaze 430

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Sagheer, the Hausmeister CodeForces - 812B

Sagheer, the Hausmeister CodeForces - 812B  题意:n层大楼,每层m个房间左右两边有一个楼梯。给出n*(m+2)的矩阵,1表示有灯0表示无灯。问人从左下角出发,关掉楼里所有灯的最短时间。每上一层楼需要1单位时间,同层每移动一格需要1单位时间。 思路:1、预处理计算最左边灯的位置和最右边灯的位置,记录最上层灯所在的层  2、想要到上一层只能从最左边或者最...

DeathYmz的博客 459

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

【CodeForces 812B --- Sagheer, the Hausmeister】DP

@ [目录](【CodeForces 812B — Sagheer,看守人】DP) 题目来源:点击进入【CodeForces 812B — Sagheer, the Hausmeister】 <字体 颜色=蓝色 大小= 5 > **说明 ** </字体> 有些人在离开时将照明留在工作场所,这是对资源的浪费。作为DHBW的代名词,Sagheer等到所有学生和教授都离开大学大楼...

来日浅谈的博客 678

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #812 (Div. 2)A,B,C

Codeforces Round #812 (Div. 2)A,B,C

weixin_62765166的博客 217

Codeforces 812 B Sagheer, the Hausmeister

题目链接:http://codeforces.com/contest/812/problem/B题意:题目中的意思就是说有一栋楼有n层每层有m个房间,两边各有一个楼梯,上下楼梯需要的时间是1分钟,从一个房间走到相邻的房间的时间是1分钟,这栋楼里有一些房间的灯是亮着的,你需要把这些灯给关掉,问你最少需要的时间是多少,你每次都是从最下面那层的左边出发,最后不需要回到起点。题解:其实直接dfs所有的状态就

不要錯過才珍惜 523

【codeforces 812B】Sagheer, the Hausmeister

【题目链接】:http://codeforces.com/contest/812/problem/B 【题意】 一个老大爷在一楼; 然后他有n楼的灯要关(最多n楼); 每楼有m个房间; 给出每个房间的灯的信息(亮或不亮) 然后他移动到相邻的房间,或者是移动到上一层都花费一分钟; 每一层的灯没有全部关掉之前,他不会往上层走; (每层的最左和最右是两个楼...

129

codeforces Sagheer, the Hausmeister 812B

题目链接: http://codeforces.com/problemset/problem/812/B 题意: 某一个楼有N层,每一层层M+2个房间,第一个房间和最后一个房间表示的是左楼梯和右楼梯。现在管理员处于最底层的左楼梯处,管理员关灯的时候有两个原则: 1.必须要将一层楼的灯全部关闭以后,才可以去上面的楼层。 2.管理员每次移动一个位置的时间均为1S,并且关灯的动作时不算时间

silver_bone的博客 322

CodeForces - 812B [DP]

这道题一开始以为是有规律的的, 想通过最大区域的0来计算,然后用bfs来解决,但是写到一半又发现思路错了,最后还是学长提醒我用dp思路去做,纪录最右和最左的点,dp已经很久没做了,看了网上其他题解才明白要怎么去维护那些状态,里面有几个点需要注意一下: 1.所有的数都为0 2.最下面楼层的dp方式不一样 3.每次dp要保存前一个的状态 因为下一次会变化 AC代码: #include&lt...

OOOak 271

CodeForces - 812B Sagheer, the Hausmeister (dp)

题目链接:http://codeforces.com/problemset/problem/812/B点击打开链接 B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input standard input

xuejye的博客 372

动态规划—— CodeForces - 812B

Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building,

你那么爱笑,家里人知道吗? 537

codeforces 812B Sagheer, the Hausmeister dp

参考某大佬的思路:dp[I][0/1]表示已经灭掉第I层的灯,并且在第I层的左/右端 #include #include #include using namespace std; const int maxn = 20; const int maxm = 110; int L[maxm],R[maxm]; int dp[maxn][2]; int main() { int n,m; cha

chen_minghui的博客 369

AC日记——Sagheer, the Hausmeister codeforces 812b

812B - Sagheer, the Hausmeister 思路:   搜索; 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define ma...

weixin_33733810的博客 114

Sagheer, the Hausmeister CodeForces - 812B dp

题目链接 思路: 只说一下这个题dp的思想吧,我们对于每一行都记录最左端未关灯的位置,和最右端未关灯的位置,那么对于左端和右端的楼梯维护一下是将本层楼灯全部关闭原路返回花的时间少,还是从右端过来时间少,对于右端也一样,然后维护一个最优解决就可以了;    坑点:在dp的时候左端被更新了会影响下面所以要记录一下初始的值.特判只有最后一行未关灯的情况 #include #inc

Marcus-Bao的个人主页 921
上一篇: HDU4565
下一篇: HDU3306
NineFailure
博客等级 码龄11年 22粉丝 317原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值