codeforces 698A Vacations 基础dp

避免踩坑!WIN11 22H2更新后共享打印机失效的终极解决方案 本文详细解析了WIN11 22H2更新后共享打印机失效的问题,特别是常见的0x00000709错误代码。通过系统更新机制分析、错误代码解读,提供从基础到高级的完整解决方案,包括注册表修复、组策略调整和驱动兼容性处理,帮助用户彻底解决打印机共享问题并预防未来故障。 阅读详情

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:

on this day the gym is closed and the contest is not carried out;
on this day the gym is closed and the contest is carried out;
on this day the gym is open and the contest is not carried out;
on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

Input
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya’s vacations.

The second line contains the sequence of integers a1, a2, …, an (0 ≤ ai ≤ 3) separated by space, where:

ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:

to do sport on any two consecutive days,
to write the contest on any two consecutive days.
Example
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.

In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.

In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Vasya有n天可以安排,0表示一定要休息,1表示可以去比赛或者休息,2表示可以去健身或者休息,3表示可以去比赛或者健身或者休息,且不能连续的两天进行竞赛或者健身,问他最少需要休息几天。

DP。
dp[i][0]表示第i天是0的最小休息天数。
dp[i][1]表示第i天是1的最小休息天数。
dp[i][2]表示第i天是2的最小休息天数。
转移方程:
dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1;

一开始全初始化为最大

#include <bits/stdc++.h>
using namespace std;
int a[101010];
int dp[101010][4];
const int INF = 0x3f3f3f3f;
int main()
{
    int n;
    cin>>n;
    memset(dp,INF,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    dp[0][0]=0;
        for(int i=1;i<=n;i++)
        {
                dp[i][0]=min(dp[i-1][1],dp[i-1][2]);
                dp[i][0]=min(dp[i][0],dp[i-1][0])+1;
            if(a[i]==1)
            {
                dp[i][1]=min(dp[i-1][2],dp[i-1][0]);
            }
            if(a[i]==2)
            {
                dp[i][2]=min(dp[i-1][0],dp[i-1][1]);
            }
            if(a[i]==3)
            {
                dp[i][2]=min(dp[i-1][1],dp[i-1][0]);
                dp[i][1]=min(dp[i-1][2],dp[i-1][0]);
            }
        }
        int res=1e9+7;
        res=min(dp[n][0],dp[n][1]);
        res=min(res,dp[n][2]);
        printf("%d\n",res );

}
MATLAB实战:利用扫频数据重构系统伯德图的关键步骤 本文详细介绍了如何利用MATLAB处理扫频数据并重构系统伯德图的完整实战流程。内容涵盖数据导入与清洗、增益与相位的精确计算、频率响应数据对象(frd)的构建、数据平滑与插值处理,以及最终生成专业伯德图并进行关键参数(如相位裕度)标注的方法。文章重点解决了从实测“黑盒子”系统数据出发,获取直观频率响应特性曲线的核心问题,为控制系统分析与设计提供了实用指南。 阅读详情

相关推荐

【STM32开源实战】基于STM32的智能输液监控系统设计与实现

本文详细介绍了基于STM32F103C8T6主控芯片的智能输液监控系统设计与实现。该系统通过光学液位传感器、温度传感器和红外滴速检测模块实时监测输液状态,利用步进电机自动调节滴速,并通过蓝牙实现数据远程传输,为医院提供了一套低成本、高可靠性的智能输液解决方案。

h6i7j8的博客 766

CodeForces 698A Vacations (动态规划)

I - Vacations Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Vasya has n days of vacations! So he decided to improve his IT ski

Calm微笑 867

用Python玩转Iris数据集:从数据加载到可视化分析的完整指南

本文提供了使用Python处理Iris数据集的完整指南,涵盖数据加载、探索性分析、特征工程和可视化呈现等关键步骤。通过Pandas、NumPy、Matplotlib和Seaborn等工具,读者将学习如何从零开始完成一个机器学习项目的数据分析流程,掌握数据科学的核心技能。

j2k3l4的博客 855

codeforces 213C Relay Race(DP基础,棋盘路径)

题意: n×n的矩阵a, −1000<=aij<=1000-1000 <= a_{ij} <= 1000 求从(1, 1)到(n,n)的两条路线(经过的格子可以重复),路线上的数值和最大,每个元素只能被取一次。 思路: 容易得出一个自然的状态表示是第k条对角线上取(k-i, i)和(k-j, j)的最大值。 用刷表法比较容易管理边界。k, i, j // 可行状态 for (int si

slowlight93的专栏 819

OCTA-500:用于光学相干断层扫描血管造影研究的视网膜数据集|文献速递-基于生成模型的数据增强与疾病监测应用

数据集提供了丰富的图像和注释,包括两种模态(OCT/OCTA体积)、六种投影类型、四种文本标签(年龄/性别/眼别/疾病)以及七种分割标签(大血管/毛细血管/动脉/静脉/2D FAZ/3D FAZ/视网膜层)。我们介绍了新的 OCTA-500 数据集,该数据集包含来自 500 名受试者的 OCTA 成像,并提供了丰富的图像和标注集。(C) OCTA-500 切片的人工标注示例。图 4. OCTA-500 数据集中文本标签的统计直方图:(a) 性别,(b) 眼别,(c) 年龄,(d) 疾病。

weixin_38594676的博客 1447

别再傻傻分不清!用R语言5分钟搞定RR、AR、OR的计算与解读(附代码)

本文通过R语言实战演示,详细讲解了RR(相对风险)、AR(绝对风险)和OR(比值比)的计算方法与科学解读。提供完整的代码示例和可视化技巧,帮助医学研究者快速掌握这些核心流行病学指标的应用与常见陷阱规避。

weixin_42526015的博客 273

codeforces 710E Generate a String(基础DP)

传送门:E. Generate a String 题目大意 : 就是从0开始 每次可以+1或-1或*2 +-操作花费x *2操作花费y 问你达到n的最小花费是多少? 解题思路 : 就是DP DP 的时候只要从0遍历到n即可 因为题目的数据范围是1e7 所以并不会超时 转移的时候一共决策三种状态 就是 1.由i-1 转移过来的 2.由i/2 转移过来的 这时候要区分下

魔笛手的博客 453

【N32L40X】学习笔记12-规则组+注入组+外部触发启动

使用定时器触发规则通道开始采集数据,采集完成后使用dma传输数据,并启动注入通道转换数据,注入通道转换完成后产生中断,中断中读物注入通道数据。

Car12 426

队内第一次集训——基础DP(讲义篇)

之前比赛吃太多DP的亏了....好多题都看不出DP,还有的是看出来了但是动态转移方程推不出来,所以在此准备先恶补DP...废话不多说,开始正题DP其实就是,把一个大问题分解成若干子问题,通过解决若干子问题来获得最终结果,这样说起来有点像分治,但实际上并不是,因为DP需要每一步都保留目前的最优解,同时满足无后效性。无后效性就是过去已经考虑过的情况就不会对后面产生影响了,直接就不用理他们。通过每一步都...

smilestruggler_Fly To Higher 485

SAP-MM-供应商对账平台(功能集合)

(1)集成OA审批,线上核销,结果写入SAP; (2)集成SRM,线上与供应商对账确认,写入SAP; (3)集成财务付款结果确认写入,OA回传结果,定时同步SRM供应商平台。 欢迎留言交流,功能完善,如需要页面设计,请订阅专栏

qq_32198063的博客 750

基于Simulink进行光伏逆变器效率分析的仿真建模

特点能量转换:将光伏电池板产生的直流电转换为交流电。效率评估:分析逆变器在不同负载条件和环境条件下的效率。动态特性:考虑温度、光照强度等外部因素对逆变器效率的影响。挑战精确建模:准确地模拟光伏电池板、逆变器及其交互的动力学过程。多因素考量:需要同时考虑输入电压、电流、温度、光照强度等多种因素对逆变器效率的影响。集成度:需要与其他系统(如最大功率点跟踪MPPT算法、电网连接等)无缝集成,以实现全面的系统分析。首先明确要模拟的任务内容。输入条件(如光照强度、温度等)。

amy_mhd的博客 144

CodeForces_455A Boredom ( 基础dp )

文章目录题意题解代码 题目连接 vj or cf 题意 题解 代码

♡ 脚下的每一步都叫远方 ♡ 294

Qt C++ + Qt 3D 的数字孪生工厂

以下是一个基于 **Qt C++ + Qt 3D** 的数字孪生工厂完整源码示例,集成了 **Qt 3D** 产线建模和 **WebSocket** 实时数据交互。ui->qualifiedProductsLabel->setText(QString("合格产品: %1").arg(data.qualifiedProducts));ui->totalProductsLabel->setText(QString("总产量: %1").arg(data.totalProducts));

寒寒豆豆软件公司的博客 153

CodeForces - 698A Vacations 贪心 dp

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was

liluoyu_1016的博客 409

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

CodeForces - 698A ——Vacations(dp)

Vasya hasndays of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of thisndays: whether that gym opened and whether a contest was c...

red_red_red的博客 173

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Codeforces 698A:Vacations(DP)

题目链接:http://codeforces.com/problemset/problem/698/A 题意 Vasya在n天中,有三件事情可以做,健身、比赛或者休息,但是不能连续两天都是比赛或都是但是健身,但是连续休息两天是允许的,问题是在这n天中,Vasya最少可以休息几天? 0代表休息,1代表比赛,2代表健身,3可以代表比赛也可以代表健身 思路 用数组dp[i][j]表示第i天...

执念 310

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Codeforces 698A Vacations DP

Codeforces 698A Vacations DP CF

阑珊记忆 414

Codeforces 698A Vacations(线性DP)

题意: 每一天都有各种活动,也可以选择休息,问你如何安排才能够在前后两天惊醒的活动不一样的情况下,是的休息的天数最少。 分析: 直接暴力进行dp就可以了,注意前后活动不一样是的转移状态的不同。 // Created by CQU_CST_WuErli // Copyright (c) 2016 CQU_CST_WuErli. All rights reserved. // //#pra

只玩三国的程序猿的专栏 596

Codeforces 698A. Vacations (简单DP)

题目链接题意每天有四种状态 0-不能运动 不能写代码 1-可以运动 不能写代码 2-不能运动 可以写代码 3-可以运动 可以写代码不能连续两天运动或连续两天写代码。 问最少的休息天数思路dp[i][k] 代表第i天干第k种事的最小休息天数,如果当天不能干该种事情,则置为inf,剩下的转移方程为 dp[i+1][0]=min(min(dp[i][0],dp[i][1]),dp[i][2])

我为刀俎_题为鱼肉 416

CodeForces 698 A. Vacations(dp)

Description 小明有n天假期,每天可以编程和运动,也可以休息,只有有编程作业的时候才能编程,体育馆开的时候才能运动,但小明不会连续两天编程或运动,现在给出n天每天的状态,问小明最少休息多少天 Input 第一行一个整数n表示假期天数,第二行n个整数(0,1,2,3)表示每天的状态 0.体育馆关门,没有编程作业 1.体育馆关门,有编程作业 2.体育馆开门,没有编程作业 3.体育

ZSQ 473

CodeForces 698A Vacations

2016暑期集训3-DCodeForces 698A多个状态同时DP 传送门:HustOJ 传送门:CodeForce 题意小崔同学很喜欢运动,也很喜欢打比赛,他每天只能选择一种活动。但是体育馆并不是每天都开,比赛也不是天天有。并且他不想连续两天做相同的事情(除了歇着。。。),输入 n 天,每天的状态(4种),求小崔休息的最少天数。思路 状态 f[i][j]表示前i天,第i天做了j事

P.H.S 354

2016 北邮暑期训练3-D题(Codeforces 698A Vacations)DP,水题

Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a c

1202

Code Forces 698A Vacations

Code Forces 698A Vacations 题目描述 Vasya has nn days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this ...

Dijkstra_Liu 203

CF698A - Vacations

题目链接 https://codeforces.com/problemset/problem/698/A 题目大意 (翻译来自luogu) 解题思路 假设Vasya每天都可以去[休息,比赛,健身],我们分别用数字[0,1,2]表示这三个项目,很容易就可以构建起问题的模型。 根据输入的样例1: 4 1 3 2 0 由题目给出的限制条件,我们可以得到下面的一个图模型: 比较暴力的作法是枚举上面模型的所有路径,统计每条路径中休息的天数,从中找一个答案最小的即可。 但是仔细观察的话可以发现模型是一个DAG

Zerotogether的博客 553

CF698A. Vacations【DP】

题目链接http://codeforces.com/problemset/problem/698/A思路设dp[i][j]表示在第i天干第j种事情,前i天的最小休息天数。 j=0表示休息,1打代码,2运动。不可能的状态置为INF,转移方程就很简单了,具体见代码。 比赛时愣是没想到用dp,早上瞄一眼题解才发现这么简单,总归还是太弱了。AC代码#include <iostream> #include

初涉_代码世界 1044
上一篇: codeforces 559B Equivalent Strings (最小表示法)
下一篇: zoj 3778 Talented Chef (思维)
黑码
博客等级 码龄10年 76粉丝 454原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值